diff --git a/src/builder/arg.rs b/src/builder/arg.rs index 4f4d9f24..bb84bc79 100644 --- a/src/builder/arg.rs +++ b/src/builder/arg.rs @@ -76,7 +76,6 @@ pub struct Arg<'help> { pub(crate) possible_vals: Vec>, pub(crate) val_names: Vec<&'help str>, pub(crate) num_vals: Option, - pub(crate) max_occurs: Option, pub(crate) max_vals: Option, pub(crate) min_vals: Option, pub(crate) validator: Option>>>, @@ -780,25 +779,6 @@ impl<'help> Arg<'help> { } } - /// Deprecated, for flags this is replaced with `action(ArgAction::Count).value_parser(value_parser!(u8).range(..max))` - #[inline] - #[must_use] - #[cfg_attr( - feature = "deprecated", - deprecated( - since = "3.2.0", - note = "For flags, replaced with `action(ArgAction::Count).value_parser(value_parser!(u8).range(..max))`" - ) - )] - pub fn max_occurrences(mut self, qty: usize) -> Self { - self.max_occurs = Some(qty); - if qty > 1 { - self.multiple_occurrences(true) - } else { - self - } - } - /// Check if the [`ArgSettings`] variant is currently set on the argument. /// /// [`ArgSettings`]: crate::ArgSettings diff --git a/src/error/context.rs b/src/error/context.rs index 985cd4d7..4b2223c1 100644 --- a/src/error/context.rs +++ b/src/error/context.rs @@ -18,10 +18,6 @@ pub enum ContextKind { ExpectedNumValues, /// Minimum number of allowed values MinValues, - /// Number of occurrences present - ActualNumOccurrences, - /// Maximum number of allowed occurrences - MaxOccurrences, /// Potential fix for the user SuggestedCommand, /// Potential fix for the user diff --git a/src/error/kind.rs b/src/error/kind.rs index 1929e457..1acbd4c8 100644 --- a/src/error/kind.rs +++ b/src/error/kind.rs @@ -175,24 +175,6 @@ pub enum ErrorKind { /// [`Arg::min_values`]: crate::Arg::min_values() TooFewValues, - /// Occurs when a user provides more occurrences for an argument than were defined by setting - /// [`Arg::max_occurrences`]. - /// - /// # Examples - /// - /// ```rust - /// # use clap::{Command, Arg, ErrorKind}; - /// let result = Command::new("prog") - /// .arg(Arg::new("verbosity") - /// .short('v') - /// .max_occurrences(2)) - /// .try_get_matches_from(vec!["prog", "-vvv"]); - /// assert!(result.is_err()); - /// assert_eq!(result.unwrap_err().kind(), ErrorKind::TooManyOccurrences); - /// ``` - /// [`Arg::max_occurrences`]: crate::Arg::max_occurrences() - TooManyOccurrences, - /// Occurs when the user provides a different number of values for an argument than what's /// been defined by setting [`Arg::number_of_values`] or than was implicitly set by /// [`Arg::value_names`]. @@ -403,7 +385,6 @@ impl ErrorKind { Self::ValueValidation => Some("Invalid value for one of the arguments"), Self::TooManyValues => Some("An argument received an unexpected value"), Self::TooFewValues => Some("An argument requires more values"), - Self::TooManyOccurrences => Some("An argument occurred too many times"), Self::WrongNumberOfValues => Some("An argument received too many or too few values"), Self::ArgumentConflict => { Some("An argument cannot be used with one or more of the other specified arguments") diff --git a/src/error/mod.rs b/src/error/mod.rs index c9cf8e3f..aa817bc5 100644 --- a/src/error/mod.rs +++ b/src/error/mod.rs @@ -352,29 +352,6 @@ impl Error { .extend_context_unchecked([(ContextKind::Usage, ContextValue::String(usage))]) } - pub(crate) fn too_many_occurrences( - cmd: &Command, - arg: String, - max_occurs: usize, - curr_occurs: usize, - usage: String, - ) -> Self { - Self::new(ErrorKind::TooManyOccurrences) - .with_cmd(cmd) - .extend_context_unchecked([ - (ContextKind::InvalidArg, ContextValue::String(arg)), - ( - ContextKind::MaxOccurrences, - ContextValue::Number(max_occurs as isize), - ), - ( - ContextKind::ActualNumValues, - ContextValue::Number(curr_occurs as isize), - ), - (ContextKind::Usage, ContextValue::String(usage)), - ]) - } - pub(crate) fn too_many_values(cmd: &Command, val: String, arg: String, usage: String) -> Self { Self::new(ErrorKind::TooManyValues) .with_cmd(cmd) @@ -689,29 +666,6 @@ impl Error { } } ErrorKind::InvalidUtf8 => false, - ErrorKind::TooManyOccurrences => { - let invalid_arg = self.get_context(ContextKind::InvalidArg); - let actual_num_occurs = self.get_context(ContextKind::ActualNumOccurrences); - let max_occurs = self.get_context(ContextKind::MaxOccurrences); - if let ( - Some(ContextValue::String(invalid_arg)), - Some(ContextValue::Number(actual_num_occurs)), - Some(ContextValue::Number(max_occurs)), - ) = (invalid_arg, actual_num_occurs, max_occurs) - { - let were_provided = Error::singular_or_plural(*actual_num_occurs as usize); - c.none("The argument '"); - c.warning(invalid_arg); - c.none("' allows at most "); - c.warning(max_occurs.to_string()); - c.none(" occurrences but "); - c.warning(actual_num_occurs.to_string()); - c.none(were_provided); - true - } else { - false - } - } ErrorKind::TooManyValues => { let invalid_arg = self.get_context(ContextKind::InvalidArg); let invalid_value = self.get_context(ContextKind::InvalidValue); diff --git a/src/parser/validator.rs b/src/parser/validator.rs index d1242d62..dab84d92 100644 --- a/src/parser/validator.rs +++ b/src/parser/validator.rs @@ -333,24 +333,6 @@ impl<'help, 'cmd> Validator<'help, 'cmd> { .create_usage_with_title(&[]), )); } - if let Some(max_occurs) = a.max_occurs { - debug!( - "Validator::validate_arg_num_occurs: max_occurs set...{}", - max_occurs - ); - let occurs = ma.get_occurrences() as usize; - if occurs > max_occurs { - return Err(Error::too_many_occurrences( - self.cmd, - a.to_string(), - max_occurs, - occurs, - Usage::new(self.cmd) - .required(&self.required) - .create_usage_with_title(&[]), - )); - } - } Ok(()) }