mirror of
https://github.com/clap-rs/clap
synced 2024-12-13 22:32:33 +00:00
refactor(parser): Ensure action and are are in-sync
This commit is contained in:
parent
7264bf28c7
commit
2b95985161
2 changed files with 19 additions and 0 deletions
|
@ -7,3 +7,14 @@ pub(crate) enum ArgAction {
|
|||
Help,
|
||||
Version,
|
||||
}
|
||||
|
||||
impl ArgAction {
|
||||
pub(crate) fn takes_value(&self) -> bool {
|
||||
match self {
|
||||
Self::StoreValue => true,
|
||||
Self::IncOccurrence => false,
|
||||
Self::Help => false,
|
||||
Self::Version => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -642,6 +642,14 @@ fn assert_arg(arg: &Arg) {
|
|||
arg.name,
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
arg.get_action().takes_value(),
|
||||
arg.is_takes_value_set(),
|
||||
"Argument `{}`'s selected action {:?} contradicts `takes_value`",
|
||||
arg.name,
|
||||
arg.get_action()
|
||||
);
|
||||
|
||||
if arg.get_value_hint() != ValueHint::Unknown {
|
||||
assert!(
|
||||
arg.is_takes_value_set(),
|
||||
|
|
Loading…
Reference in a new issue