-
-
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
ArgRequiredElseHelp is ignored if there are *any* default values #1264
Comments
I think perhaps https://github.com/kbknapp/clap-rs/blob/master/src/app/validator.rs#L63 should use I dropped a PR in #1265; all tests pass still and the issue appears fixed. I'm not familiar enough to know if this is the best approach, so let me know of any feedback. Edit: actually that PR appears to render the help menu too frequently now, so closed for the time being :) |
Sorry for the long wait, I've been away for a few weeks with my day job. while I agree it's not optimal, a default value is a value and therefore clap treats it as such. I'd possibly consider adding some sort of setting such as |
Bringing this back because I found this issue when searching before opening a new one. Versions: @kbknapp: if the "fix" is to call I believe Is there any use case where It seems to me that clap's approach to default values is equating them with the user passing them in the command line (with the exception of |
@CreepySkeleton you were working on default stuff recently, right? Can you take a look at this last comment? |
I find myself agreeing with @Kayvlim . Default values aren't ephemeral, they are very real values. Clap treats them in almost exactly the same way as any other value (barring conflict resolution which they are exempt from, or at least should have been).
That is a good question. My answer would be no, there aren't, and in this case we should panic if |
@CreepySkeleton I suppose you are only agreeing with how I think clap works, but not with how I think it should be changed? I don't agree that If the user runs my application without arguments, I want them to see the help, but if they run it with the single required argument, I want the application to run with a sensible set of default values for the arguments they didn't pass (or "override"). I shouldn't have to So, I think In other words, I don't see default values as values the user positively intended to pass to the application by omission. I see them as values the application needs to assume when the user hasn't said anything about them and |
Well, let's see what we can do about that... |
I was bitten by this issue myself while trying to add ArgRequiredElseHelp to a CLI. It's wholly unintuitive - both to the user and the developer - that the use of default values would be considered sufficient to bypass this check. |
See issues linked from #3076 for other default handling issues. |
Rust Version
rustc 1.25.0 (84203cac6 2018-03-25)
Affected Version of clap
2.31.2
Expected Behavior Summary
If
ArgRequiredElseHelp
is enabled, you should see the help menu if an option is not provided correctly.Actual Behavior Summary
If you have two arguments, and one has a default, this the help menu is not correctly printed.
Steps to Reproduce the issue
Run the code below in a test project via
cargo run
. It won't work (rightly so) because the "second" option is not provided - but you'll get an error instead of the help menu.Do the same again with the default value removed from "first", and you'll then see a help menu. Regardless of the default value of "first", it should show the help menu both times.
The text was updated successfully, but these errors were encountered: