This commit is contained in:
Ahmed Ilyas 2025-07-05 16:25:16 -04:00 committed by GitHub
commit 4d5dca9ec8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -2197,11 +2197,30 @@ where
}
}
let args = args.into_iter().collect::<Vec<_>>();
let matches = Cli::command()
.mut_arg("help", |arg| arg.action(clap::ArgAction::SetTrue))
.ignore_errors(true)
.try_get_matches_from(args.clone());
let no_color = matches.is_ok_and(|arg| {
matches!(
arg.try_get_one::<uv_cli::ColorChoice>("color"),
Ok(Some(uv_cli::ColorChoice::Never))
) || matches!(arg.try_get_one::<bool>("no_color"), Ok(Some(true)))
});
// `std::env::args` is not `Send` so we parse before passing to our runtime
// https://github.com/rust-lang/rust/pull/48005
let cli = match Cli::try_parse_from(args) {
Ok(cli) => cli,
Err(mut err) => {
let cmd = if no_color {
Cli::command()
.color(clap::ColorChoice::Never)
.disable_colored_help(true)
} else {
Cli::command()
};
err = err.with_cmd(&cmd);
if let Some(ContextValue::String(subcommand)) = err.get(ContextKind::InvalidSubcommand)
{
match subcommand.as_str() {