refactor(parser): Split up parsing from post-processing

This commit is contained in:
Ed Page 2024-11-11 13:11:29 -06:00
parent 6827841930
commit a1d69ca824

View file

@ -50,9 +50,29 @@ impl<'cmd> Parser<'cmd> {
&mut self,
matcher: &mut ArgMatcher,
raw_args: &mut clap_lex::RawArgs,
mut args_cursor: clap_lex::ArgCursor,
args_cursor: clap_lex::ArgCursor,
) -> ClapResult<()> {
debug!("Parser::get_matches_with");
ok!(self.parse(matcher, raw_args, args_cursor));
ok!(self.resolve_pending(matcher));
#[cfg(feature = "env")]
ok!(self.add_env(matcher));
ok!(self.add_defaults(matcher));
Validator::new(self.cmd).validate(matcher)
}
// The actual parsing function
#[allow(clippy::cognitive_complexity)]
pub(crate) fn parse(
&mut self,
matcher: &mut ArgMatcher,
raw_args: &mut clap_lex::RawArgs,
mut args_cursor: clap_lex::ArgCursor,
) -> ClapResult<()> {
debug!("Parser::parse");
// Verify all positional assertions pass
let mut subcmd_name: Option<String> = None;
@ -436,11 +456,7 @@ impl<'cmd> Parser<'cmd> {
matches: sc_m.into_inner(),
});
ok!(self.resolve_pending(matcher));
#[cfg(feature = "env")]
ok!(self.add_env(matcher));
ok!(self.add_defaults(matcher));
return Validator::new(self.cmd).validate(matcher);
return Ok(());
} else {
// Start error processing
let _ = self.resolve_pending(matcher);
@ -474,11 +490,7 @@ impl<'cmd> Parser<'cmd> {
ok!(self.parse_subcommand(&sc_name, matcher, raw_args, args_cursor, keep_state));
}
ok!(self.resolve_pending(matcher));
#[cfg(feature = "env")]
ok!(self.add_env(matcher));
ok!(self.add_defaults(matcher));
Validator::new(self.cmd).validate(matcher)
Ok(())
}
fn match_arg_error(