fix(parser): SetFalse should also not allow self-override

This commit is contained in:
Ed Page 2022-09-28 16:21:08 -05:00
parent bf42ff04d5
commit 2d7874948f
3 changed files with 9 additions and 2 deletions

View file

@ -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::<bool>("flag").copied(),

View file

@ -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(),

View file

@ -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::<bool>("mammal").unwrap(), false);