Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve interactions between color environment variables and CLI options #8215

Merged
merged 3 commits into from
Oct 21, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions crates/uv/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,17 @@ 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 matches!(
args.color,
ColorChoice::Always | ColorChoice::Never | ColorChoice::Auto
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this will always be true, right? We might need to make color: Option<ColorChoice> to distinguish the none case.

Copy link
Contributor Author

@Aditya-PS-05 Aditya-PS-05 Oct 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thaught, if we have passed --color then it doesn't depend what is the value as it will always be used.

I thought if

error: invalid value 'none' for '--color <COLOR_CHOICE>'
  [possible values: auto, always, never]

For more information, try '--help'.

If only three values are defined. then no need to show support for none

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or this is a possibly new issue?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This value will always be populated because Clap fills in the default regardless of whether or not the user explicitly passed a value.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to bring this up at #8183 (comment) but I think you misunderstood

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made

pub color: Option<ColorChoice>,
if let Some(color_choice) = args.color {
                // If `--color` is passed explicitly, use its value.
                color_choice
            }

Everything is working as expected.

) {
// `--color` is passed explicitly, use `args.color`.
args.color
} 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 +93,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
Loading