diff --git a/crates/uv-cli/src/lib.rs b/crates/uv-cli/src/lib.rs index af1013724b14..77b6783645aa 100644 --- a/crates/uv-cli/src/lib.rs +++ b/crates/uv-cli/src/lib.rs @@ -179,7 +179,7 @@ pub struct GlobalArgs { conflicts_with = "no_color", value_name = "COLOR_CHOICE" )] - pub color: ColorChoice, + pub color: Option, /// Whether to load TLS certificates from the platform's native certificate store. /// diff --git a/crates/uv/src/settings.rs b/crates/uv/src/settings.rs index d9bde2a2a030..a24e32e45a79 100644 --- a/crates/uv/src/settings.rs +++ b/crates/uv/src/settings.rs @@ -74,11 +74,14 @@ impl GlobalSettings { Self { quiet: args.quiet, verbose: args.verbose, - color: if args.no_color - || std::env::var_os(EnvVars::NO_COLOR) - .filter(|v| !v.is_empty()) - .is_some() + color: if let Some(color_choice) = args.color { + // If `--color` is passed explicitly, use its value. + color_choice + } else if std::env::var_os(EnvVars::NO_COLOR) + .filter(|v| !v.is_empty()) + .is_some() { + // If the `NO_COLOR` is set, disable color output. ColorChoice::Never } else if std::env::var_os(EnvVars::FORCE_COLOR) .filter(|v| !v.is_empty()) @@ -87,9 +90,10 @@ impl GlobalSettings { .filter(|v| !v.is_empty()) .is_some() { + // If `FORCE_COLOR` or `CLICOLOR_FORCE` is set, always enable color output. ColorChoice::Always } else { - args.color + ColorChoice::Auto }, native_tls: flag(args.native_tls, args.no_native_tls) .combine(workspace.and_then(|workspace| workspace.globals.native_tls))