fix!: Make is_multiple_values private

multiple_values is now just book keeping for the builder, instead people
should look to actions and `num_args`.

The meaning for it was a little weird anyways.
This commit is contained in:
Ed Page 2022-08-04 14:53:42 -05:00
parent 6e1ca59ec1
commit 32f308d4ef
4 changed files with 23 additions and 22 deletions

View file

@ -622,7 +622,8 @@ fn write_positionals_of(p: &Command) -> String {
for arg in p.get_positionals() {
debug!("write_positionals_of:iter: arg={}", arg.get_id());
let cardinality = if arg.is_multiple_values_set() {
let num_args = arg.get_num_args().expect("built");
let cardinality = if num_args != 1.into() && num_args != 0.into() {
"*:"
} else if !arg.is_required_set() {
":"

View file

@ -334,7 +334,8 @@ fn gen_args(arg: &Arg, indent: usize) -> String {
indent = indent
));
if arg.is_multiple_values_set() {
let num_args = arg.get_num_args().expect("built");
if num_args != 0.into() && num_args != 1.into() {
buffer.push_str(&format!(
"{:indent$}isVariadic: true,\n",
"",

View file

@ -3790,8 +3790,7 @@ impl<'help> Arg<'help> {
self.is_set(ArgSettings::Required)
}
/// Report whether [`Arg::num_args`] allows multiple values
pub fn is_multiple_values_set(&self) -> bool {
pub(crate) fn is_multiple_values_set(&self) -> bool {
self.is_set(ArgSettings::MultipleValues)
}

View file

@ -44,7 +44,7 @@ mod arg {
assert_eq!(arg.get_id(), "foo");
assert_eq!(arg.get_short(), Some('b'));
assert!(matches!(arg.get_action(), clap::ArgAction::SetTrue));
assert!(!arg.is_multiple_values_set());
assert_eq!(arg.get_num_args(), None);
assert!(!arg.is_required_set());
assert_eq!(arg.get_help(), None);
@ -52,7 +52,7 @@ mod arg {
assert_eq!(arg.get_id(), "foo");
assert_eq!(arg.get_short(), Some('b'));
assert!(matches!(arg.get_action(), clap::ArgAction::SetTrue));
assert!(!arg.is_multiple_values_set());
assert_eq!(arg.get_num_args(), None);
assert!(!arg.is_required_set());
assert_eq!(arg.get_help(), None);
@ -60,7 +60,7 @@ mod arg {
assert_eq!(arg.get_id(), "foo");
assert_eq!(arg.get_short(), Some('b'));
assert!(matches!(arg.get_action(), clap::ArgAction::Count));
assert!(!arg.is_multiple_values_set());
assert_eq!(arg.get_num_args(), None);
assert!(!arg.is_required_set());
assert_eq!(arg.get_help(), None);
@ -68,7 +68,7 @@ mod arg {
assert_eq!(arg.get_id(), "foo");
assert_eq!(arg.get_short(), Some('b'));
assert!(matches!(arg.get_action(), clap::ArgAction::SetTrue));
assert!(!arg.is_multiple_values_set());
assert_eq!(arg.get_num_args(), None);
assert!(!arg.is_required_set());
assert_eq!(arg.get_help(), Some("How to use it"));
}
@ -80,7 +80,7 @@ mod arg {
assert_eq!(arg.get_long(), Some("hello"));
assert_eq!(arg.get_short(), Some('b'));
assert!(matches!(arg.get_action(), clap::ArgAction::SetTrue));
assert!(!arg.is_multiple_values_set());
assert_eq!(arg.get_num_args(), None);
assert!(!arg.is_required_set());
assert_eq!(arg.get_help(), None);
@ -89,7 +89,7 @@ mod arg {
assert_eq!(arg.get_long(), Some("hello"));
assert_eq!(arg.get_short(), Some('b'));
assert!(matches!(arg.get_action(), clap::ArgAction::SetTrue));
assert!(!arg.is_multiple_values_set());
assert_eq!(arg.get_num_args(), None);
assert!(!arg.is_required_set());
assert_eq!(arg.get_help(), None);
@ -98,7 +98,7 @@ mod arg {
assert_eq!(arg.get_long(), Some("hello"));
assert_eq!(arg.get_short(), Some('b'));
assert!(matches!(arg.get_action(), clap::ArgAction::Count));
assert!(!arg.is_multiple_values_set());
assert_eq!(arg.get_num_args(), None);
assert!(!arg.is_required_set());
assert_eq!(arg.get_help(), None);
@ -107,7 +107,7 @@ mod arg {
assert_eq!(arg.get_long(), Some("hello"));
assert_eq!(arg.get_short(), Some('b'));
assert!(matches!(arg.get_action(), clap::ArgAction::SetTrue));
assert!(!arg.is_multiple_values_set());
assert_eq!(arg.get_num_args(), None);
assert!(!arg.is_required_set());
assert_eq!(arg.get_help(), Some("How to use it"));
}
@ -118,7 +118,7 @@ mod arg {
assert_eq!(arg.get_id(), "foo");
assert_eq!(arg.get_short(), Some('b'));
assert!(matches!(arg.get_action(), clap::ArgAction::Set));
assert!(!arg.is_multiple_values_set());
assert_eq!(arg.get_num_args(), None);
assert!(arg.is_required_set());
assert_eq!(arg.get_help(), None);
@ -126,7 +126,7 @@ mod arg {
assert_eq!(arg.get_id(), "foo");
assert_eq!(arg.get_short(), Some('b'));
assert!(matches!(arg.get_action(), clap::ArgAction::Set));
assert!(!arg.is_multiple_values_set());
assert_eq!(arg.get_num_args(), None);
assert!(arg.is_required_set());
assert_eq!(arg.get_help(), None);
@ -134,7 +134,7 @@ mod arg {
assert_eq!(arg.get_id(), "foo");
assert_eq!(arg.get_short(), Some('b'));
assert!(matches!(arg.get_action(), clap::ArgAction::Append));
assert!(!arg.is_multiple_values_set());
assert_eq!(arg.get_num_args(), None);
assert!(arg.is_required_set());
assert_eq!(arg.get_help(), None);
@ -142,7 +142,7 @@ mod arg {
assert_eq!(arg.get_id(), "foo");
assert_eq!(arg.get_short(), Some('b'));
assert!(matches!(arg.get_action(), clap::ArgAction::Set));
assert!(!arg.is_multiple_values_set());
assert_eq!(arg.get_num_args(), None);
assert!(arg.is_required_set());
assert_eq!(arg.get_help(), Some("How to use it"));
}
@ -153,7 +153,7 @@ mod arg {
assert_eq!(arg.get_id(), "NUM");
assert_eq!(arg.get_value_names(), Some(vec!["NUM"].as_slice()));
assert!(matches!(arg.get_action(), clap::ArgAction::Set));
assert!(!arg.is_multiple_values_set());
assert_eq!(arg.get_num_args(), None);
assert!(arg.is_required_set());
assert_eq!(arg.get_help(), None);
@ -161,7 +161,7 @@ mod arg {
assert_eq!(arg.get_id(), "NUM");
assert_eq!(arg.get_value_names(), Some(vec!["NUM"].as_slice()));
assert!(matches!(arg.get_action(), clap::ArgAction::Set));
assert!(!arg.is_multiple_values_set());
assert_eq!(arg.get_num_args(), None);
assert!(!arg.is_required_set());
assert_eq!(arg.get_help(), None);
@ -169,7 +169,7 @@ mod arg {
assert_eq!(arg.get_id(), "NUM");
assert_eq!(arg.get_value_names(), Some(vec!["NUM"].as_slice()));
assert!(matches!(arg.get_action(), clap::ArgAction::Set));
assert!(!arg.is_multiple_values_set());
assert_eq!(arg.get_num_args(), None);
assert!(arg.is_required_set());
assert_eq!(arg.get_help(), None);
@ -177,7 +177,7 @@ mod arg {
assert_eq!(arg.get_id(), "foo");
assert_eq!(arg.get_value_names(), Some(vec!["NUM"].as_slice()));
assert!(matches!(arg.get_action(), clap::ArgAction::Set));
assert!(!arg.is_multiple_values_set());
assert_eq!(arg.get_num_args(), None);
assert!(arg.is_required_set());
assert_eq!(arg.get_help(), None);
@ -185,7 +185,7 @@ mod arg {
assert_eq!(arg.get_id(), "NUM");
assert_eq!(arg.get_value_names(), Some(vec!["NUM"].as_slice()));
assert!(matches!(arg.get_action(), clap::ArgAction::Append));
assert!(arg.is_multiple_values_set());
assert_eq!(arg.get_num_args(), Some((1..).into()));
assert!(arg.is_required_set());
assert_eq!(arg.get_help(), None);
@ -193,7 +193,7 @@ mod arg {
assert_eq!(arg.get_id(), "NUM");
assert_eq!(arg.get_value_names(), Some(vec!["NUM"].as_slice()));
assert!(matches!(arg.get_action(), clap::ArgAction::Set));
assert!(!arg.is_multiple_values_set());
assert_eq!(arg.get_num_args(), None);
assert!(arg.is_required_set());
assert_eq!(arg.get_help(), Some("How to use it"));
}