From e3153e303940267b14f918482576e62ee6024e8c Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 4 Aug 2022 16:10:10 -0500 Subject: [PATCH] refactor: We don't need MultipleValues for bookkeeping afterall TakesValue helps because it provides a way for a lot of settings to say a value is needed without specifying how many. Multiple values didn't have enough call sites to make this worthwhile. This is a part of #2688 --- src/builder/arg.rs | 26 +++++--------------------- src/builder/arg_settings.rs | 3 --- 2 files changed, 5 insertions(+), 24 deletions(-) diff --git a/src/builder/arg.rs b/src/builder/arg.rs index b74c9a1d6cd..86bcec039f8 100644 --- a/src/builder/arg.rs +++ b/src/builder/arg.rs @@ -874,16 +874,6 @@ impl<'help> Arg<'help> { self } - #[inline] - #[must_use] - fn multiple_values(self, yes: bool) -> Self { - if yes { - self.setting(ArgSettings::MultipleValues) - } else { - self.unset_setting(ArgSettings::MultipleValues) - } - } - /// Specifies the number of arguments parsed per occurrence /// /// For example, if you had a `-f ` argument where you wanted exactly 3 'files' you would @@ -1035,7 +1025,6 @@ impl<'help> Arg<'help> { let qty = qty.into(); self.num_vals = Some(qty); self.takes_value(qty.takes_values()) - .multiple_values(qty.is_multiple()) } /// Placeholder for the argument's value in the help message / usage. @@ -1461,11 +1450,9 @@ impl<'help> Arg<'help> { /// [`Arg::last(true)`]: Arg::last() #[inline] #[must_use] - pub fn raw(self, yes: bool) -> Self { - self.takes_value(yes) - .multiple_values(yes) - .allow_hyphen_values(yes) - .last(yes) + pub fn raw(mut self, yes: bool) -> Self { + self.num_vals.get_or_insert_with(|| (1..).into()); + self.takes_value(yes).allow_hyphen_values(yes).last(yes) } /// Value for the argument when not present. @@ -3791,7 +3778,7 @@ impl<'help> Arg<'help> { } pub(crate) fn is_multiple_values_set(&self) -> bool { - self.is_set(ArgSettings::MultipleValues) + self.get_num_args().unwrap_or_default().is_multiple() } pub(crate) fn is_takes_value_set(&self) -> bool { @@ -3955,12 +3942,9 @@ impl<'help> Arg<'help> { let val_names_len = self.val_names.len(); if val_names_len > 1 { - self.settings.set(ArgSettings::MultipleValues); self.num_vals.get_or_insert(val_names_len.into()); } else { - if self.is_multiple_values_set() { - self.num_vals.get_or_insert((1..).into()); - } else if self.is_takes_value_set() { + if self.is_takes_value_set() { self.num_vals.get_or_insert(1.into()); } else { self.num_vals.get_or_insert(0.into()); diff --git a/src/builder/arg_settings.rs b/src/builder/arg_settings.rs index a3d55a217ba..693b8b6db51 100644 --- a/src/builder/arg_settings.rs +++ b/src/builder/arg_settings.rs @@ -28,7 +28,6 @@ impl Default for ArgFlags { #[non_exhaustive] pub(crate) enum ArgSettings { Required, - MultipleValues, Global, Hidden, TakesValue, @@ -66,7 +65,6 @@ bitflags! { const HIDE_ENV_VALS = 1 << 17; const HIDDEN_SHORT_H = 1 << 18; const HIDDEN_LONG_H = 1 << 19; - const MULTIPLE_VALS = 1 << 20; #[cfg(feature = "env")] const HIDE_ENV = 1 << 21; const EXCLUSIVE = 1 << 23; @@ -76,7 +74,6 @@ bitflags! { impl_settings! { ArgSettings, ArgFlags, Required => Flags::REQUIRED, - MultipleValues => Flags::MULTIPLE_VALS, Global => Flags::GLOBAL, Hidden => Flags::HIDDEN, TakesValue => Flags::TAKES_VAL,