diff --git a/src/builder/action.rs b/src/builder/action.rs index dc7b79a7..01d1f07b 100644 --- a/src/builder/action.rs +++ b/src/builder/action.rs @@ -169,7 +169,7 @@ pub enum ArgAction { /// .action(clap::ArgAction::SetFalse) /// ); /// - /// let matches = cmd.clone().try_get_matches_from(["mycmd", "--flag", "--flag"]).unwrap(); + /// let matches = cmd.clone().try_get_matches_from(["mycmd", "--flag"]).unwrap(); /// assert!(matches.contains_id("flag")); /// assert_eq!( /// matches.get_one::("flag").copied(), diff --git a/src/parser/parser.rs b/src/parser/parser.rs index fb43923f..24550db2 100644 --- a/src/parser/parser.rs +++ b/src/parser/parser.rs @@ -1240,7 +1240,7 @@ impl<'cmd> Parser<'cmd> { raw_vals }; - if matcher.remove(&arg.id) && self.cmd.is_args_override_self() { + if matcher.remove(&arg.id) && !self.cmd.is_args_override_self() { return Err(ClapError::argument_conflict( self.cmd, arg.to_string(), diff --git a/tests/builder/action.rs b/tests/builder/action.rs index d9b24873..4c5bf810 100644 --- a/tests/builder/action.rs +++ b/tests/builder/action.rs @@ -240,8 +240,15 @@ fn set_false() { assert_eq!(matches.contains_id("mammal"), true); assert_eq!(matches.index_of("mammal"), Some(1)); + let result = cmd + .clone() + .try_get_matches_from(["test", "--mammal", "--mammal"]); + let err = result.err().unwrap(); + assert_eq!(err.kind(), ErrorKind::ArgumentConflict); + let matches = cmd .clone() + .args_override_self(true) .try_get_matches_from(["test", "--mammal", "--mammal"]) .unwrap(); assert_eq!(*matches.get_one::("mammal").unwrap(), false);