Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document how to allow arguments to start with hyphens #19

Open
ngirard opened this issue Nov 6, 2020 · 3 comments
Open

Document how to allow arguments to start with hyphens #19

ngirard opened this issue Nov 6, 2020 · 3 comments
Labels
documentation Improvements or additions to documentation

Comments

@ngirard
Copy link

ngirard commented Nov 6, 2020

Using the following test script:

#!/bin/bash

# shellcheck disable=SC2154

slap deps bat confirm rg sd|| exit 1

eval "$(slap parse bash _ -- "$@" <<-EOF
name: test
version: "0.1"
about: Using an argument that contains '--'

settings:
    - ArgRequiredElseHelp
    - ColorAuto

global_settings:
    - ColoredHelp

args:
    - arg:
        help: The argument
        required: true
EOF
)"; [[ -z "${_success}" ]] && exit 1

printf -- "arg:%s\n" "${_arg_vals}"

Executing ./test value outputs var:value, but executing `./test '--value' leads to

error: Found argument '--value' which wasn't expected, or isn't valid in this context

In my scenario I need to be able to have arguments that start with --.

Is there a workaround ?

@ngirard
Copy link
Author

ngirard commented Nov 6, 2020

The solution consists in

  • adding allow_hyphen_values: true to the argument; and
  • prepending -- to the argument list in the invocation: ./test -- '--value'

I tried both separately before but not jointly.

I'm leaving this issue open because I think it would be nice to provide an example that illustrate this.

I think Slap is underrated and deserves a much wider audience, but much of them might not find it straightforward to use Clap's documentation. Adding more examples would definitely make a difference.

@ngirard ngirard changed the title Error when value of argument starts with -- Document how to allow arguments start with hyphens Nov 6, 2020
@ngirard ngirard changed the title Document how to allow arguments start with hyphens Document how to allow arguments to start with hyphens Nov 6, 2020
@guardam guardam added the documentation Improvements or additions to documentation label Nov 8, 2020
@guardam
Copy link
Owner

guardam commented Nov 8, 2020

I think it would be cool also to have some editor intellisense support, so you can see available options and what they do. See #10
This is doable because in clap's master there is a JSON schema we can use: https://github.com/clap-rs/clap/blob/master/clap.schema.json

@guardam
Copy link
Owner

guardam commented Nov 8, 2020

As for the example, as soon as I have time I'll add one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants