-
-
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
Feature: add Arg::required_unless_all #1135
Comments
From testing, this also occurs with |
Also, having multiple |
Thanks for filing! I'll start to take a look. I've been away for the holidays and traveling. @willmurphyscode I saw your test cases in the PR. Do you want to continue with this? |
@kbknapp I will start digging today. I'll ping you if I get stuck. |
@kbknapp I've been experimenting with the tests, trying to discover what is different between the passing and failing test runs, and the differences begin at this line: When there are no short or long forms of the arg that is "required_unless_one," then the arg is added as a positional, but if there are short or long forms, the arg is added as a flag. I believe that the correct behavior is accidentally dependent on the required_unless_one arg being treated as a positional and not as a flag, but I haven't figured out why yet. Does it seem like I'm on the right track? Do you have any insight as to where I might keep looking? |
@willmurphyscode You're exactly correct about that line of code, but I'm not sure if that's the issue or not. You're right, the tests don't use an arg with a short as the one that defines (required_unless_one), but that shouldn't be the issue (at least it's not supposed to be). There was recently a rework to how clap validates, so I've updated the debug output in the OP to v2.29.2 (where the error still occurs). The error seems to say |
@gbear605 can you test this against the master branch and see if it fixes it for you? @willmurphyscode has come up with a fix, and if it works I'll release the new version. |
My issue now is somewhat the opposite of before, although this may be intended behavior: It now allows me to do all the arguments I want, but it also allows me to have just one or two of them. For instance, I can pass in "-a -c" or "-a" and it works, but I instead want it to require "-x" unless all three of the other argument pairs are provided. That's what I was trying to achieve with the three calls to I would say that overall this is an improvement over before, as my issue now is not clearly a bug and the clear bug I was seeing before is now gone. My debug output now with passing in just "-a":
|
@gbear605 Let me see if I understand this issue. You basically want this behavior (in some pseudocode here):
Is that correct? Right now, |
That's correct. So, it seems that the actual bug involved here was fixed by @willmurphyscode's fix and now this is just a feature request for that behavior. |
Thanks for the work @willmurphyscode ! I'm going to remove the bug and 2.x labels. However, I'll leave this feature request open for when I'm opening the feature request window for 3.x. I have to keep blinders on or I'll never finish 3.x. |
Rust Version
rustc 1.24.0-nightly (7eb64b86c 2017-12-20)
Affected Version of clap
clap 2.29.0
Expected Behavior Summary
With the given sample app, I should be able to have the arguments:
-a -c -e
-a -c -f
-a -d -e
-a -d -f
-b -c -e
-b -c -f
-b -d -e
-b -d -f
The overall goal of the program is that I should have to call
-x
or I should have to call one from each of (-a
,-b
), (-c
,-d
), and (-e
,-f
). I should also never have both arguments from each argument group.Actual Behavior Summary
For all of those combinations above, it says:
error: The following required arguments were not provided: -x
Steps to Reproduce the issue
Create a new binary Cargo project with Clap and the provided code as main.rs, run
cargo run -- -a -c -e
(or similar with any of the above combinations)Sample Code or Link to Sample Code
Debug output
The text was updated successfully, but these errors were encountered: