mirror of
https://github.com/clap-rs/clap
synced 2025-01-21 00:53:52 +00:00
Fixes group conflicting if two args with default values
This commit is contained in:
parent
64a2866b09
commit
01869744c2
2 changed files with 21 additions and 1 deletions
|
@ -277,7 +277,7 @@ impl<'help, 'app, 'parser> Validator<'help, 'app, 'parser> {
|
||||||
.app
|
.app
|
||||||
.unroll_args_in_group(&g.id)
|
.unroll_args_in_group(&g.id)
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|&a| matcher.contains(a))
|
.filter(|&a| matcher.contains(a) && !matcher.is_default_value(a))
|
||||||
.count()
|
.count()
|
||||||
> 1
|
> 1
|
||||||
};
|
};
|
||||||
|
|
|
@ -285,6 +285,26 @@ fn group_in_conflicts_with() {
|
||||||
assert_eq!(m.value_of("opt"), Some("default"));
|
assert_eq!(m.value_of("opt"), Some("default"));
|
||||||
assert!(m.is_present("flag"));
|
assert!(m.is_present("flag"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn group_conflicts_with_default_value() {
|
||||||
|
let result = App::new("conflict")
|
||||||
|
.arg(
|
||||||
|
Arg::new("opt")
|
||||||
|
.long("opt")
|
||||||
|
.default_value("default")
|
||||||
|
.group("one"),
|
||||||
|
)
|
||||||
|
.arg(Arg::new("flag").long("flag").group("one"))
|
||||||
|
.try_get_matches_from(vec!["myprog", "--flag"]);
|
||||||
|
|
||||||
|
assert!(result.is_ok(), "{:?}", result.unwrap());
|
||||||
|
let m = result.unwrap();
|
||||||
|
|
||||||
|
assert_eq!(m.value_of("opt"), Some("default"));
|
||||||
|
assert!(m.is_present("flag"));
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn group_conflicts_with_default_arg() {
|
fn group_conflicts_with_default_arg() {
|
||||||
let result = App::new("conflict")
|
let result = App::new("conflict")
|
||||||
|
|
Loading…
Reference in a new issue