-
Notifications
You must be signed in to change notification settings - Fork 0
Feature: add Arg::required_unless_all #85
Comments
Comment by willmurphyscode I believe this is an issue where |
Comment by gbear605 From testing, this also occurs with |
Comment by gbear605 Also, having multiple |
Comment by kbknapp 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? |
Comment by willmurphyscode @kbknapp I will start digging today. I'll ping you if I get stuck. |
Comment by willmurphyscode @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? |
Comment by kbknapp @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 |
Comment by kbknapp @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. |
Comment by gbear605 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":
|
Comment by willmurphyscode @gbear605 Let me see if I understand this issue. You basically want this behavior (in some pseudocode here):
Is that correct? Right now, |
Comment by gbear605 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. |
Comment by kbknapp 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. |
Issue by gbear605
Friday Dec 22, 2017 at 10:43 GMT
Originally opened as clap-rs/clap#1135
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: