diff --git a/src/parse/parser.rs b/src/parse/parser.rs index c6b83a06f3d..4678fdddb4b 100644 --- a/src/parse/parser.rs +++ b/src/parse/parser.rs @@ -448,7 +448,10 @@ impl<'help, 'cmd> Parser<'help, 'cmd> { matches: sc_m.into_inner(), }); - return Validator::new(self).validate(parse_state, matcher, trailing_values); + #[cfg(feature = "env")] + self.add_env(matcher, trailing_values)?; + self.add_defaults(matcher, trailing_values); + return Validator::new(self).validate(parse_state, matcher); } else { // Start error processing return Err(self.match_arg_error(&arg_os, valid_arg_found, trailing_values)); @@ -465,7 +468,10 @@ impl<'help, 'cmd> Parser<'help, 'cmd> { self.parse_subcommand(&sc_name, matcher, raw_args, args_cursor, keep_state)?; } - Validator::new(self).validate(parse_state, matcher, trailing_values) + #[cfg(feature = "env")] + self.add_env(matcher, trailing_values)?; + self.add_defaults(matcher, trailing_values); + Validator::new(self).validate(parse_state, matcher) } fn match_arg_error( diff --git a/src/parse/validator.rs b/src/parse/validator.rs index f3f902ce592..ac07100eb49 100644 --- a/src/parse/validator.rs +++ b/src/parse/validator.rs @@ -23,17 +23,11 @@ impl<'help, 'cmd, 'parser> Validator<'help, 'cmd, 'parser> { &mut self, parse_state: ParseState, matcher: &mut ArgMatcher, - trailing_values: bool, ) -> ClapResult<()> { debug!("Validator::validate"); let mut conflicts = Conflicts::new(); let has_subcmd = matcher.subcommand_name().is_some(); - #[cfg(feature = "env")] - self.p.add_env(matcher, trailing_values)?; - - self.p.add_defaults(matcher, trailing_values); - if let ParseState::Opt(a) = parse_state { debug!("Validator::validate: needs_val_of={:?}", a);