mirror of
https://github.com/clap-rs/clap
synced 2024-12-13 14:22:34 +00:00
refactor(validate): Clarify subcmd check intent
This commit is contained in:
parent
8e5ce6c044
commit
c0fd6753ea
2 changed files with 5 additions and 10 deletions
|
@ -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(
|
||||
|
|
|
@ -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)?;
|
||||
|
|
Loading…
Reference in a new issue