commandeer
commandeer copied to clipboard
Can't pass in an empty string to an option
commandline:
option variableA, string, "var", "v", "default"
# none of the following work
executable --var:
# out: Missing value for option 'var'
executable --var=
# out: Missing value for option 'var'
executable --var ""
# out: Couldn't convert '' to string
There should only be an error if the user hasn't explicitly given a blank value, like the following
executable --var
# out: Missing value for option 'var'
I have been thinking about this for a while now. I agree we need a way to override a default string option to a given empty string... but it is non-trivial. I say that because of the following:
1- there is a need to establish what we want -- studying the behaviour of other classic CLI (C/Python) would be the next step (see below)
2- the basic CLI parsing is controlled by the underlying parseopt standard library -- implementing our own or contributing to the standard library might be needed
3- the standard library has at least one bug (see below)
| CLI | should do | does |
|---|---|---|
| --option="" tree | option == "" and argument == "tree" | option == "tree" argument missing |
| --option='' tree | option == "" and argument == "tree" | option == "tree" argument missing |
| --option "" tree | option == "" and argument == "tree" | couldn't convert '' to string for option |
| --option= tree | missing option for --option OR option == "" OR option == "tree" | option == "tree" argument missing |
| --option="" --anotherOption tree | option == "" and argument == "tree" | option == "--anotherOption" argument == "tree" -- this is a bug in the standard library |
| --option= --anotherOption tree | missing option for --option OR option == "" OR option == "--anotherOption" and argument == "tree" | option == "--anotherOption" argument == "tree" |
| --option --anotherOption tree | missing option for --option OR option == "" and argument == "tree" | missing value for option 'option' |
For all the "should do" with "OR" cases, we would need to look at how it is done typically and if it makes sense.
Some links for reference
The primary Python framework Click
The nim stdlib parseopt seems to be very reminiscent of getopt which has always been fairly restrictive (POSIX only requires single letter flags/options, so the tooling for that has been similarly limited), so probably opting for a custom parsing library would give the best sanest result
Also worth noting that the argument passing mechanisms differ between OSes. (e.g. windows doesn't really have an understanding of what quoting is) so that is a potential issue