TeXitoi / structopt

Parse command line arguments by defining a struct.
Other
2.7k stars 149 forks source link

Is it possible to escape dash + space when used as value of a positional character? #534

Closed ifraixedes closed 9 months ago

ifraixedes commented 9 months ago

Using a project called amber which uses structopt, I realized that passing a value beginning with - (dash + blank space) doesn't get parsed properly as a positional argument.

See https://github.com/dalance/amber/issues/299

I'm wondering if there is a way to skip that sequence or is a bug or not accepting values beginning with - is intentional.

Thank you!

TeXitoi commented 9 months ago

Hi.

First, structopt is in maintenance mode, so better to update the library.

Second, clap v2 is the parsing backend, so that would be the place to ask. clap v2 is outdated, clap v3 is the new solution (that include its version of structopt).

Finally, this is expected behavior, and quite standard in argument parsing: flags and options (argument begining by -) are not needed to be before positional argument. So you can for example grep expr -i that would be equivalent to grep -i expr. To stop parsing arguments as options and flags, you can use the -- special argument meaning "stop parsing the argument after as options and flags, they are positional argument only".

So, the TLDR is: Just call

$ ambr -- '* ' '- ' .