diff --git a/clap_builder/src/parser/matches/matched_arg.rs b/clap_builder/src/parser/matches/matched_arg.rs index a9cc0d3406a..20614542a86 100644 --- a/clap_builder/src/parser/matches/matched_arg.rs +++ b/clap_builder/src/parser/matches/matched_arg.rs @@ -132,10 +132,6 @@ impl MatchedArg { self.vals.last().map(|x| x.len()).unwrap_or(0) } - pub(crate) fn all_val_groups_empty(&self) -> bool { - self.vals.iter().flatten().count() == 0 - } - pub(crate) fn check_explicit(&self, predicate: &ArgPredicate) -> bool { if self.source.map(|s| !s.is_explicit()).unwrap_or(false) { return false; diff --git a/clap_builder/src/parser/mod.rs b/clap_builder/src/parser/mod.rs index 3e73544d5a4..faec2f0266e 100644 --- a/clap_builder/src/parser/mod.rs +++ b/clap_builder/src/parser/mod.rs @@ -12,8 +12,8 @@ pub(crate) mod features; pub(crate) use self::arg_matcher::ArgMatcher; pub(crate) use self::matches::{MatchedArg, SubCommand}; pub(crate) use self::parser::Identifier; +pub(crate) use self::parser::Parser; pub(crate) use self::parser::PendingArg; -pub(crate) use self::parser::{ParseState, Parser}; pub(crate) use self::validator::get_possible_values_cli; pub(crate) use self::validator::Validator; diff --git a/clap_builder/src/parser/parser.rs b/clap_builder/src/parser/parser.rs index 69970683ef3..164a21c98f4 100644 --- a/clap_builder/src/parser/parser.rs +++ b/clap_builder/src/parser/parser.rs @@ -440,7 +440,7 @@ impl<'cmd> Parser<'cmd> { #[cfg(feature = "env")] ok!(self.add_env(matcher)); ok!(self.add_defaults(matcher)); - return Validator::new(self.cmd).validate(parse_state, matcher); + return Validator::new(self.cmd).validate(matcher); } else { // Start error processing let _ = self.resolve_pending(matcher); @@ -478,7 +478,7 @@ impl<'cmd> Parser<'cmd> { #[cfg(feature = "env")] ok!(self.add_env(matcher)); ok!(self.add_defaults(matcher)); - Validator::new(self.cmd).validate(parse_state, matcher) + Validator::new(self.cmd).validate(matcher) } fn match_arg_error( diff --git a/clap_builder/src/parser/validator.rs b/clap_builder/src/parser/validator.rs index d62fd8109ed..43552c926d0 100644 --- a/clap_builder/src/parser/validator.rs +++ b/clap_builder/src/parser/validator.rs @@ -3,7 +3,7 @@ use crate::builder::StyledStr; use crate::builder::{Arg, ArgGroup, ArgPredicate, Command, PossibleValue}; use crate::error::{Error, Result as ClapResult}; use crate::output::Usage; -use crate::parser::{ArgMatcher, ParseState}; +use crate::parser::ArgMatcher; use crate::util::ChildGraph; use crate::util::FlatMap; use crate::util::FlatSet; @@ -21,37 +21,11 @@ impl<'cmd> Validator<'cmd> { Validator { cmd, required } } - pub(crate) fn validate( - &mut self, - parse_state: ParseState, - matcher: &mut ArgMatcher, - ) -> ClapResult<()> { + pub(crate) fn validate(&mut self, matcher: &mut ArgMatcher) -> ClapResult<()> { debug!("Validator::validate"); let conflicts = Conflicts::with_args(self.cmd, matcher); let has_subcmd = matcher.subcommand_name().is_some(); - if let ParseState::Opt(a) = parse_state { - debug!("Validator::validate: needs_val_of={a:?}"); - - let o = &self.cmd[&a]; - let should_err = if let Some(v) = matcher.args.get(o.get_id()) { - v.all_val_groups_empty() && o.get_min_vals() != 0 - } else { - true - }; - if should_err { - return Err(Error::empty_value( - self.cmd, - &get_possible_values_cli(o) - .iter() - .filter(|pv| !pv.is_hide_set()) - .map(|n| n.get_name().to_owned()) - .collect::>(), - o.to_string(), - )); - } - } - if !has_subcmd && self.cmd.is_arg_required_else_help_set() { let num_user_values = matcher .args()