From 31815a25920dd2d6ef1c8511a2316ced81f2dc27 Mon Sep 17 00:00:00 2001 From: Aditya Pratap Singh Date: Mon, 21 Oct 2024 22:34:49 +0530 Subject: [PATCH] Improve interactions between color environment variables and CLI options (#8215) closes #8173 --- crates/uv-cli/src/lib.rs | 2 +- crates/uv/src/settings.rs | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/crates/uv-cli/src/lib.rs b/crates/uv-cli/src/lib.rs index c3498965f2b9..901d73981bf1 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 5b731cb6ea34..703193eb6f3c 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))