Improve interactions between color environment variables and CLI options (#8215)

closes #8173
This commit is contained in:
Aditya Pratap Singh
2024-10-21 22:34:49 +05:30
committed by Zanie Blue
parent 55502842c0
commit b622315a6c
2 changed files with 10 additions and 6 deletions
+1 -1
View File
@@ -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.
///
+9 -5
View File
@@ -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))