Skip to content

Commit 7638829

Browse files
Aditya-PS-05charliermarsh
authored andcommitted
Improve interactions between color environment variables and CLI options (#8215)
closes #8173
1 parent 16d99fa commit 7638829

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

crates/uv-cli/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ pub struct GlobalArgs {
179179
conflicts_with = "no_color",
180180
value_name = "COLOR_CHOICE"
181181
)]
182-
pub color: ColorChoice,
182+
pub color: Option<ColorChoice>,
183183

184184
/// Whether to load TLS certificates from the platform's native certificate store.
185185
///

crates/uv/src/settings.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,14 @@ impl GlobalSettings {
7474
Self {
7575
quiet: args.quiet,
7676
verbose: args.verbose,
77-
color: if args.no_color
78-
|| std::env::var_os(EnvVars::NO_COLOR)
79-
.filter(|v| !v.is_empty())
80-
.is_some()
77+
color: if let Some(color_choice) = args.color {
78+
// If `--color` is passed explicitly, use its value.
79+
color_choice
80+
} else if std::env::var_os(EnvVars::NO_COLOR)
81+
.filter(|v| !v.is_empty())
82+
.is_some()
8183
{
84+
// If the `NO_COLOR` is set, disable color output.
8285
ColorChoice::Never
8386
} else if std::env::var_os(EnvVars::FORCE_COLOR)
8487
.filter(|v| !v.is_empty())
@@ -87,9 +90,10 @@ impl GlobalSettings {
8790
.filter(|v| !v.is_empty())
8891
.is_some()
8992
{
93+
// If `FORCE_COLOR` or `CLICOLOR_FORCE` is set, always enable color output.
9094
ColorChoice::Always
9195
} else {
92-
args.color
96+
ColorChoice::Auto
9397
},
9498
native_tls: flag(args.native_tls, args.no_native_tls)
9599
.combine(workspace.and_then(|workspace| workspace.globals.native_tls))

0 commit comments

Comments
 (0)