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
requires_all ArgGroup with a default, causes the entire ArgGroup to be required #1586
Comments
any progress on this? |
I think this is the expected behaviour. Default value just behaves as if the user is always using it. If clap special case it, you will see an use clap::*;
fn main() {
let _matches = App::new("bin")
.arg(
Arg::new("foo")
.required(false)
.long("foo")
.value_name("FOO")
.takes_value(true),
)
.arg(
Arg::new("bar")
.required(false)
.long("bar")
.value_name("BAR")
.takes_value(true),
)
.arg(
Arg::new("baz")
.required(false)
.long("baz")
.value_name("BAZ")
.default_value("default value")
.takes_value(true),
)
.group(
ArgGroup::new("test_flags")
.multiple(true)
.args(&["foo", "bar", "baz"])
.requires_all(&["baz"]),
)
.get_matches();
assert_eq!(_matches.value_of("test_flags"), Some("default value"));
} |
This is meant to lower the chance of confusion with cases like clap-rs#2714 and clap-rs#1586. This is not meant to be exhaustive, looked at the mentioned cases in that issue and pattern matched on other ones mentioning "is present".
This is related to #2714 and I am reducing the impact through documentation in #2896. I assume @pksunkara will want this to remain open as part of future work to try to resolve this, |
This is meant to lower the chance of confusion with cases like clap-rs#2714 and clap-rs#1586. This is not meant to be exhaustive, looked at the mentioned cases in that issue and pattern matched on other ones mentioning "is present".
This is meant to lower the chance of confusion with cases like clap-rs#2714 and clap-rs#1586. This is not meant to be exhaustive, looked at the mentioned cases in that issue and pattern matched on other ones mentioning "is present".
Rust Version
rustc 1.40.0-nightly (10a52c25c 2019-10-24)
Affected Version of clap
clap 2.33.0
Expected Behavior Summary
ArgGroup
to make 3 flags required to use together, if at all. Eg,--foo
and--bar
are optional, but if specified at all--foo
and--bar
must both have a value.--baz
has a default value, in the same group of--foo
and--bar
.Actual Behavior Summary
The default value of
--baz
seems to make theArgGroup
behave as if the user is always attempting to use it. Such that theArgGroup
becomes required. Example:Steps to Reproduce the issue
Run the sample code, with no flags specified.
Sample Code or Link to Sample Code
Debug output
Debug Output
The text was updated successfully, but these errors were encountered: