-
-
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
Internal error when using conflicts_with
with ArgGroup
#3197
Comments
Backported this to clap2 and it works use clap::{App, Arg, ArgGroup};
fn main() {
let m = App::new("demoapp")
.arg(
Arg::with_name("foo")
.long("foo")
.conflicts_with("argument-group"),
)
.arg(Arg::with_name("bar").long("bar"))
.group(ArgGroup::with_name("argument-group").arg("bar"))
.get_matches();
dbg!(m);
} Its interesting the panic in clap3 happens with Debug output:
|
We handle conflicts in two phases
There is some deleted code in |
Found this when digging into clap-rs#3197
We are looping over the arguments set by the parser. In one case, we are checking to see if the argument is a group. I am not seeing us set groups in the matcher when parsing and we have a debug assert ensuring arg and group names don't conflict. This looks like dead code to me. I am hesitant making a change like this right before release but this is part of trying to make the code understandable for root causing and fixing clap-rs#3197
Found this when digging into clap-rs#3197
We are looping over the arguments set by the parser. In one case, we are checking to see if the argument is a group. I am not seeing us set groups in the matcher when parsing and we have a debug assert ensuring arg and group names don't conflict. This looks like dead code to me. I am hesitant making a change like this right before release but this is part of trying to make the code understandable for root causing and fixing clap-rs#3197
The crux of the issue is how we communicate between the two phases (gather, check): we gather groups for both present args and that conflict with present args. These become contradictory. What I'm trying to understand next is why the algorithm shifted so much from clap v2 |
3.0.0-rc.8 is released with the fix for this |
Please complete the following tasks
Rust Version
rustc 1.57.0 (f1edd0429 2021-11-29)
Clap Version
3.0.0-rc.7
Minimal reproducible code
Steps to reproduce the bug with the above code
cargo run -- --foo
Actual Behaviour
The program panics, with the following internal error:
Expected Behaviour
The program should work, outputting something like
Additional Context
I am trying to make a single argument conflict with a
ArgGroup
(to save on repetition). If I instead place theconflicts_with("foo")
on the argument group definition, it works as expected.I'm assuming using the
conflicts_with
method on the individual argument should be possible too, but if it isn't supposed to be possible, a better error message would be good.Debug Output
The text was updated successfully, but these errors were encountered: