refactor(parser): Ensure action and are are in-sync

This commit is contained in:
Ed Page 2022-05-31 15:17:21 -05:00
parent 7264bf28c7
commit 2b95985161
2 changed files with 19 additions and 0 deletions

View file

@ -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,
}
}
}

View file

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