diff --git a/clap_builder/src/builder/command.rs b/clap_builder/src/builder/command.rs index 5756e7dfd84..71ea73c0e3b 100644 --- a/clap_builder/src/builder/command.rs +++ b/clap_builder/src/builder/command.rs @@ -3810,7 +3810,7 @@ impl Command { // do the real parsing let mut parser = Parser::new(self); if let Err(error) = parser.get_matches_with(&mut matcher, raw_args, args_cursor) { - if self.is_set(AppSettings::IgnoreErrors) { + if self.is_set(AppSettings::IgnoreErrors) && error.use_stderr() { debug!("Command::_do_parse: ignoring error: {error}"); } else { return Err(error); diff --git a/tests/builder/ignore_errors.rs b/tests/builder/ignore_errors.rs index 3103ad519ad..014149948df 100644 --- a/tests/builder/ignore_errors.rs +++ b/tests/builder/ignore_errors.rs @@ -1,5 +1,7 @@ use clap::{arg, Arg, ArgAction, Command}; +use super::utils; + #[test] fn single_short_arg_without_value() { let cmd = Command::new("cmd").ignore_errors(true).arg(arg!( @@ -124,3 +126,24 @@ fn subcommand() { Some("some other val") ); } + +#[test] +fn help_command() { + static HELP: &str = "\ +Usage: test + +Options: + -h, --help Print help +"; + + let cmd = Command::new("test").ignore_errors(true); + + utils::assert_output(cmd, "test --help", HELP, false); +} + +#[test] +fn version_command() { + let cmd = Command::new("test").ignore_errors(true).version("0.1"); + + utils::assert_output(cmd, "test --version", "test 0.1\n", false); +}