Skip to content

Commit

Permalink
Improve interactions between color environment variables and CLI opti…
Browse files Browse the repository at this point in the history
…ons (#8215)

closes #8173
  • Loading branch information
Aditya-PS-05 authored and zanieb committed Nov 4, 2024
1 parent 0c9fdf0 commit 2f5824f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion crates/uv-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ pub struct GlobalArgs {
conflicts_with = "no_color",
value_name = "COLOR_CHOICE"
)]
pub color: ColorChoice,
pub color: Option<ColorChoice>,

/// Whether to load TLS certificates from the platform's native certificate store.
///
Expand Down
14 changes: 9 additions & 5 deletions crates/uv/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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))
Expand Down

0 comments on commit 2f5824f

Please sign in to comment.