refactor(parser): Clarify Action::Flag's behavior

This commit is contained in:
Ed Page 2022-05-31 15:11:24 -05:00
parent eeca653697
commit 7264bf28c7
3 changed files with 4 additions and 4 deletions

View file

@ -3,7 +3,7 @@
#[non_exhaustive]
pub(crate) enum ArgAction {
StoreValue,
Flag,
IncOccurrence,
Help,
Version,
}

View file

@ -4159,7 +4159,7 @@ impl<'help> App<'help> {
let action = super::ArgAction::StoreValue;
a.action = Some(action);
} else {
let action = super::ArgAction::Flag;
let action = super::ArgAction::IncOccurrence;
a.action = Some(action);
}
}

View file

@ -1167,7 +1167,7 @@ impl<'help, 'cmd> Parser<'help, 'cmd> {
}
Ok(ParseResult::ValuesDone)
}
ArgAction::Flag => {
ArgAction::IncOccurrence => {
debug_assert_eq!(raw_vals, Vec::<OsString>::new());
if source == ValueSource::CommandLine {
if matches!(ident, Some(Identifier::Short) | Some(Identifier::Long)) {
@ -1264,7 +1264,7 @@ impl<'help, 'cmd> Parser<'help, 'cmd> {
} else {
match arg.get_action() {
ArgAction::StoreValue => unreachable!("{:?} is not a flag", arg.get_id()),
ArgAction::Flag => {
ArgAction::IncOccurrence => {
debug!("Parser::add_env: Found a flag with value `{:?}`", val);
let predicate = str_to_bool(val.to_str_lossy());
debug!("Parser::add_env: Found boolean literal `{:?}`", predicate);