Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: We don't need MultipleValues for bookkeeping afterall #4031

Merged
merged 1 commit into from Aug 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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