slap
slap copied to clipboard
Document how to allow arguments to start with hyphens
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 ?
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.
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
As for the example, as soon as I have time I'll add one.