Disable color for invalid commands with --color=never

This commit is contained in:
Ahmed Ilyas 2024-10-23 12:55:29 +02:00 committed by konstin
parent 8f5803e703
commit fc8e41fbeb

View file

@ -2003,7 +2003,13 @@ where
let cli = match Cli::try_parse_from(args) { let cli = match Cli::try_parse_from(args) {
Ok(cli) => cli, Ok(cli) => cli,
Err(mut err) => { Err(mut err) => {
let cmd = Cli::command().disable_colored_help(no_color); let cmd = if no_color {
Cli::command()
.color(clap::ColorChoice::Never)
.disable_colored_help(true)
} else {
Cli::command()
};
err = err.with_cmd(&cmd); err = err.with_cmd(&cmd);
if let Some(ContextValue::String(subcommand)) = err.get(ContextKind::InvalidSubcommand) if let Some(ContextValue::String(subcommand)) = err.get(ContextKind::InvalidSubcommand)
{ {