Skip to content

Commit

Permalink
refactor: We don't need MultipleValues for bookkeeping afterall
Browse files Browse the repository at this point in the history
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 clap-rs#2688
  • Loading branch information
epage committed Aug 4, 2022
1 parent fcbcafc commit e3153e3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 24 deletions.
26 changes: 5 additions & 21 deletions src/builder/arg.rs
Expand Up @@ -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 <file>` argument where you wanted exactly 3 'files' you would
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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());
Expand Down
3 changes: 0 additions & 3 deletions src/builder/arg_settings.rs
Expand Up @@ -28,7 +28,6 @@ impl Default for ArgFlags {
#[non_exhaustive]
pub(crate) enum ArgSettings {
Required,
MultipleValues,
Global,
Hidden,
TakesValue,
Expand Down Expand Up @@ -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;
Expand All @@ -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,
Expand Down

0 comments on commit e3153e3

Please sign in to comment.