-
-
Notifications
You must be signed in to change notification settings - Fork 1.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 ArgGroup
is satisfied by a default value
#1205
Comments
Got into a discussion about this on IRC with @anp, pasting log: tl;dr: I still feel that
|
Thanks for all the details! Yeah, unfortunately I don't want to change the behavior as a default value is a value. However, I can add I can take a look at adding it once v3 is out. I'd like to think on the ramifications of |
This sounds like a logic problem to me: having a default value implies that the arg or group is NOT required - why the hell would it have a default value otherwise? If a default value was specified, it's implied that there's circumstance this default value would be used in, but if the arg was also required, than the default value would never be used - user would be forced to supply their own value. Having I think we should panic (maybe only in debug?) if both have been detected on one arg/group. |
This is how a normal |
@CreepySkeleton Is this issue fixed? I remember you fixing something about this. |
@CreepySkeleton I disagree specifically in the case of I gave a specific use case in my second comment, which is inexpressible with Clap's current behavior, as far as I can tell:
This is a use case that arose from me trying to re-implement an existing tool in Rust using Clap, and it is (so far as I can tell) an eminently sensible behavior. The issue here is perhaps the conflation of "a default value for an optional argument to a flag" with "a default value if a flag is not passed at all", where the latter should satisfy an |
Gotcha. And this is exactly why we're introducing |
@eternaleye , to read up the impetus and semantics of the new |
Closing this since the needed API is already added. |
@pksunkara This issue is a reminder to add a check:
|
Rust Version
1.24.1
Affected Version of clap
2.31.1
Expected Behavior Summary
I'd expect that an
ArgGroup
withrequired(true)
would fail unless the user explicitly passed an argument, even if one of the arguments sets adefault_value
. The documentation notes that this can be done by checkingoccurrences_of
.Actual Behavior Summary
If one argument of the group sets a
default_value
, the group is satisfied.Steps to Reproduce the issue
App
with two arguments, one of which takes a defaulted value.required(true)
Sample Code or Link to Sample Code
The text was updated successfully, but these errors were encountered: