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

Can't pass in an empty string to an option #20

Open
Summertime opened this issue Oct 20, 2018 · 2 comments
Open

Can't pass in an empty string to an option #20

Summertime opened this issue Oct 20, 2018 · 2 comments

Comments

@Summertime
Copy link

Summertime commented Oct 20, 2018

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'
@fenekku
Copy link
Owner

fenekku commented Nov 4, 2018

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.

@Summertime
Copy link
Author

Some links for reference

POSIX's rough guide

The primary Python framework Click

The stdlib for Python3


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

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

No branches or pull requests

2 participants