Revert "Revert "Fixes arg conflicting with group whose arg has default value""

This reverts commit 706085d9c5.
This commit is contained in:
Pavan Kumar Sunkara 2021-11-03 18:52:35 +00:00
parent b86aa631be
commit 0b7def675b
2 changed files with 28 additions and 4 deletions

View file

@ -284,10 +284,11 @@ impl<'help, 'app, 'parser> Validator<'help, 'app, 'parser> {
};
let conf_with_arg = || g.conflicts.iter().any(|x| !matcher.is_default_value(x));
let arg_conf_with_gr = || {
matcher
.arg_names()
.filter_map(|x| self.p.app.find(x))
.any(|x| x.blacklist.iter().any(|c| *c == g.id))
!matcher.is_default_value(&g.id)
&& matcher
.arg_names()
.filter_map(|x| self.p.app.find(x))
.any(|x| x.blacklist.iter().any(|c| *c == g.id))
};
conf_with_self() || conf_with_arg() || arg_conf_with_gr()
} else if let Some(ma) = matcher.get(name) {

View file

@ -271,6 +271,29 @@ fn conflicts_with_alongside_default() {
assert!(m.is_present("flag"));
}
#[test]
fn group_in_conflicts_with() {
let result = App::new("conflict")
.arg(
Arg::new("opt")
.long("opt")
.default_value("default")
.group("one"),
)
.arg(Arg::new("flag").long("flag").conflicts_with("one"))
.try_get_matches_from(vec!["myprog", "--flag"]);
assert!(
result.is_ok(),
"conflicts_with on an arg group should ignore default_value: {:?}",
result.unwrap_err()
);
let m = result.unwrap();
assert_eq!(m.value_of("opt"), Some("default"));
assert!(m.is_present("flag"));
}
#[test]
fn group_conflicts_with_default_arg() {
let result = App::new("conflict")