mirror of
https://github.com/clap-rs/clap
synced 2024-11-14 16:47:21 +00:00
fix(parser): SetFalse should also not allow self-override
This commit is contained in:
parent
bf42ff04d5
commit
2d7874948f
3 changed files with 9 additions and 2 deletions
|
@ -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(),
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue