From 64a2866b0982a5490c55113ca8324b116089b69a Mon Sep 17 00:00:00 2001 From: Pavan Kumar Sunkara Date: Mon, 25 Oct 2021 19:30:31 +0100 Subject: [PATCH] Fixes arg conflicting with group whose arg has default value --- src/parse/validator.rs | 9 +++++---- tests/conflicts.rs | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/parse/validator.rs b/src/parse/validator.rs index db9aca2e..8dbd432f 100644 --- a/src/parse/validator.rs +++ b/src/parse/validator.rs @@ -283,10 +283,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) { diff --git a/tests/conflicts.rs b/tests/conflicts.rs index b8ef5af3..2d273d26 100644 --- a/tests/conflicts.rs +++ b/tests/conflicts.rs @@ -267,6 +267,24 @@ 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(), "{:?}", result.unwrap()); + 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")