mirror of
https://github.com/clap-rs/clap
synced 2025-03-04 15:27:16 +00:00
refactor(parser): Clarify Action::Flag's behavior
This commit is contained in:
parent
eeca653697
commit
7264bf28c7
3 changed files with 4 additions and 4 deletions
|
@ -3,7 +3,7 @@
|
|||
#[non_exhaustive]
|
||||
pub(crate) enum ArgAction {
|
||||
StoreValue,
|
||||
Flag,
|
||||
IncOccurrence,
|
||||
Help,
|
||||
Version,
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Reference in a new issue