diff --git a/src/parse/parser.rs b/src/parse/parser.rs index 192f3658..9bbf56c1 100644 --- a/src/parse/parser.rs +++ b/src/parse/parser.rs @@ -468,12 +468,7 @@ impl<'help, 'app> Parser<'help, 'app> { matches: sc_m.into_inner(), }); - return Validator::new(self).validate( - parse_state, - subcmd_name.is_some(), - matcher, - trailing_values, - ); + return Validator::new(self).validate(parse_state, matcher, trailing_values); } else { // Start error processing return Err(self.match_arg_error(&arg_os, valid_arg_found, trailing_values)); @@ -501,7 +496,7 @@ impl<'help, 'app> Parser<'help, 'app> { return Err(ClapError::display_help_error(self.app, message)); } - Validator::new(self).validate(parse_state, subcmd_name.is_some(), matcher, trailing_values) + Validator::new(self).validate(parse_state, matcher, trailing_values) } fn match_arg_error( diff --git a/src/parse/validator.rs b/src/parse/validator.rs index e276f3db..50618fb6 100644 --- a/src/parse/validator.rs +++ b/src/parse/validator.rs @@ -18,11 +18,11 @@ impl<'help, 'app, 'parser> Validator<'help, 'app, 'parser> { pub(crate) fn validate( &mut self, parse_state: ParseState, - is_subcmd: bool, matcher: &mut ArgMatcher, trailing_values: bool, ) -> ClapResult<()> { debug!("Validator::validate"); + let has_subcmd = matcher.subcommand_name().is_some(); #[cfg(feature = "env")] self.p.add_env(matcher, trailing_values)?; @@ -51,7 +51,7 @@ impl<'help, 'app, 'parser> Validator<'help, 'app, 'parser> { } } - if matcher.subcommand_name().is_none() && self.p.app.is_arg_required_else_help_set() { + if !has_subcmd && self.p.app.is_arg_required_else_help_set() { let num_user_values = matcher .arg_names() .filter(|arg_id| matcher.check_explicit(arg_id, ArgPredicate::IsPresent)) @@ -62,7 +62,7 @@ impl<'help, 'app, 'parser> Validator<'help, 'app, 'parser> { } } self.validate_conflicts(matcher)?; - if !(self.p.app.is_subcommand_negates_reqs_set() && is_subcmd) { + if !(self.p.app.is_subcommand_negates_reqs_set() && has_subcmd) { self.validate_required(matcher)?; } self.validate_matched_args(matcher)?;