75lb / command-line-args

A mature, feature-complete library to parse command-line options.
MIT License
679 stars 107 forks source link

Problem with crossed options #93

Closed DavidIAm closed 5 years ago

DavidIAm commented 5 years ago

Found a parsing thing that doesn't work - it seems to get confused about having a space within a particular argv and mis-matches value?

I was trying to do somethin glike

/thing/like/a/shell -c "--instance dog"

And encountered this result.

Probably some small oversight...

75lb commented 5 years ago

i'm not sure whether there is an issue here.. to avoid ambiguity you use --option=value notation as documented here.

E.g.

$ /thing/like/a/shell --colour="--instance dog"

--option=value notation is not available for short options, so this will not work:

$ /thing/like/a/shell -c="--instance dog"
DavidIAm commented 5 years ago

There is a constraint in which this ambiguity becomes problematic in this case however - the 'you are invoking a shell' api uses -c "set of commands for the shell". I can't change the option calling format of the ssh/shell invocation software, so this ambiguity IS an issue. "don't do that" isn't an option here.

At the very least, being crystal clear about constructs that are impossible 'if you need to do this, just forget about using THIS module to parse your options', I guess?

75lb commented 5 years ago

The short option notation in this lib is inspired mostly by getopt. Getopt doesn't have an --option=value style of notation, it would parse the value as =--instance dog (keeping the =).

$ getopt c: -c="--instance dog"
 -c =--instance dog --

Passing a "set of commands for the shell" is a common use case, take a look at Terminate parsing with a double hypen.