From 67e75748446aed7bc90866b5b41a01875ea505f1 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Mon, 11 Nov 2024 13:11:29 -0600 Subject: [PATCH] fix(parser): Fill in defaults on ignored error This came up in #5812 and is especially problematic for derives. --- clap_builder/src/parser/parser.rs | 3 ++- tests/builder/ignore_errors.rs | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/clap_builder/src/parser/parser.rs b/clap_builder/src/parser/parser.rs index 74b4bcde1e3..35595da176e 100644 --- a/clap_builder/src/parser/parser.rs +++ b/clap_builder/src/parser/parser.rs @@ -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) } diff --git a/tests/builder/ignore_errors.rs b/tests/builder/ignore_errors.rs index 850699a21b0..702b7746e63 100644 --- a/tests/builder/ignore_errors.rs +++ b/tests/builder/ignore_errors.rs @@ -113,7 +113,7 @@ fn unexpected_argument() { m.get_one::("config").cloned(), Some("config file".to_owned()) ); - assert_eq!(m.get_one::("unset-flag").copied(), None); + assert_eq!(m.get_one::("unset-flag").copied(), Some(false)); } #[test]