-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
A .required(true).takes_value(true)
arg is successfully assigned no value if followed by a recognized option
#1105
Comments
Note: This looks suspiciously like #665 which was supposedly fixed. Adding
but I don't see how there is an "empty value" here, nor can I possibly imagine why an empty value would produce // by my measure...
["prog", "--pattern=", "-f"] // has an empty value
["prog", "--pattern", "", "-f"] // has an empty value
["prog", "--pattern", "-f"] // no empty value here (args in sample code above) |
Thanks for reporting this and all the details! You've correctly assessed everything. The problem stems from clap conflating two subjectively distinct versions of "empty values." As time has gone on, I've grown more opinionated about what an "empty value" is, and what should be allowed by default. I'll spare the history of why it is the way it is currently, and just state what I think it should be going forward to fix this. An empty value is one that is explicitly and intentionally blank. This would mean only the following would qualify as an empty value:
Note: Note 2: depending on the shell a single quote may work as well ( Currently, the following also qualify as an empty value, which I'm finally declaring as a bug:
Here's the summary in table form (assuming
Note the strange findings with |
In my opinion, it feels funny to even be considering I'm glad that you plan to change this case to an error, because it feels to me like a recipe for trouble to be trying to guess the user's intent based on guessing where quotes used to be in the input. |
The way Rust (or shells in general?) pass the argv to clap, Some users want the ability to pass in empty values (i.e. when a value should be required, however sometimes a blank value is what is desired). |
This is fixed in #1109 |
Rust Version
rustc 1.23.0-nightly (ee2286149 2017-11-07)
Affected Version of clap
Expected Behavior Summary
If an argument has the following settings:
then
value_of("argument")
should never beNone
. (get_matches
should fail before that ever happens)Actual Behavior Summary
If such an argument is followed by a valid option, then
get_matches()
succeeds, butvalue_of("argument")
isNone
.(note: arguments with
allow_hyphen_values(true)
are not affected, as in that case it interprets the option as being the argument's value)Sample Code or Link to Sample Code
playground
Debug output
The text was updated successfully, but these errors were encountered: