Skip to content

Commit

Permalink
fix(parser): Fill in defaults on ignored error
Browse files Browse the repository at this point in the history
This came up in #5812 and is especially problematic for derives.
  • Loading branch information
epage committed Nov 12, 2024
1 parent 026f188 commit 67e7574
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion clap_builder/src/parser/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,14 @@ impl<'cmd> Parser<'cmd> {
) -> ClapResult<()> {
debug!("Parser::get_matches_with");

ok!(self.parse(matcher, raw_args, args_cursor));
let res = 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));

res?;
Validator::new(self.cmd).validate(matcher)
}

Expand Down
2 changes: 1 addition & 1 deletion tests/builder/ignore_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ fn unexpected_argument() {
m.get_one::<String>("config").cloned(),
Some("config file".to_owned())
);
assert_eq!(m.get_one::<bool>("unset-flag").copied(), None);
assert_eq!(m.get_one::<bool>("unset-flag").copied(), Some(false));
}

#[test]
Expand Down

0 comments on commit 67e7574

Please sign in to comment.