From f7fc85f4e95369b6919293d1df9b7b6531cde55b Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Sun, 5 Jan 2025 21:18:16 -0500 Subject: [PATCH] Respect `FORCE_COLOR` environment variable (#10315) ## Summary Closes https://github.com/astral-sh/uv/issues/10303. --- crates/uv-cli/src/lib.rs | 9 +- crates/uv/tests/it/help.rs | 22 ++--- docs/reference/cli.md | 195 ++++++++++++++++++++++--------------- 3 files changed, 133 insertions(+), 93 deletions(-) diff --git a/crates/uv-cli/src/lib.rs b/crates/uv-cli/src/lib.rs index bddc6a5f7..ade2d43ac 100644 --- a/crates/uv-cli/src/lib.rs +++ b/crates/uv-cli/src/lib.rs @@ -171,12 +171,13 @@ pub struct GlobalArgs { #[arg(global = true, long, hide = true, conflicts_with = "color")] pub no_color: bool, - /// Control colors in output. + /// Control the use of color in output. + /// + /// By default, uv will automatically detect support for colors when writing to a terminal. #[arg( global = true, long, value_enum, - default_value = "auto", conflicts_with = "no_color", value_name = "COLOR_CHOICE" )] @@ -4486,8 +4487,8 @@ pub struct GenerateShellCompletionArgs { pub quiet: bool, #[arg(long, short, action = clap::ArgAction::Count, conflicts_with = "quiet", hide = true)] pub verbose: u8, - #[arg(long, default_value = "auto", conflicts_with = "no_color", hide = true)] - pub color: ColorChoice, + #[arg(long, conflicts_with = "no_color", hide = true)] + pub color: Option, #[arg(long, hide = true)] pub native_tls: bool, #[arg(long, hide = true)] diff --git a/crates/uv/tests/it/help.rs b/crates/uv/tests/it/help.rs index 31e3e02d4..93b6ece02 100644 --- a/crates/uv/tests/it/help.rs +++ b/crates/uv/tests/it/help.rs @@ -52,7 +52,7 @@ fn help() { -v, --verbose... Use verbose output --color - Control colors in output [default: auto] [possible values: auto, always, never] + Control the use of color in output [possible values: auto, always, never] --native-tls Whether to load TLS certificates from the platform's native certificate store [env: UV_NATIVE_TLS=] @@ -132,7 +132,7 @@ fn help_flag() { -v, --verbose... Use verbose output --color - Control colors in output [default: auto] [possible values: auto, always, never] + Control the use of color in output [possible values: auto, always, never] --native-tls Whether to load TLS certificates from the platform's native certificate store [env: UV_NATIVE_TLS=] @@ -211,7 +211,7 @@ fn help_short_flag() { -v, --verbose... Use verbose output --color - Control colors in output [default: auto] [possible values: auto, always, never] + Control the use of color in output [possible values: auto, always, never] --native-tls Whether to load TLS certificates from the platform's native certificate store [env: UV_NATIVE_TLS=] @@ -347,9 +347,9 @@ fn help_subcommand() { () --color - Control colors in output + Control the use of color in output. - [default: auto] + By default, uv will automatically detect support for colors when writing to a terminal. Possible values: - auto: Enables colored output only when the output is going to a terminal or TTY with @@ -591,9 +591,9 @@ fn help_subsubcommand() { () --color - Control colors in output + Control the use of color in output. - [default: auto] + By default, uv will automatically detect support for colors when writing to a terminal. Possible values: - auto: Enables colored output only when the output is going to a terminal or TTY with @@ -728,7 +728,7 @@ fn help_flag_subcommand() { -v, --verbose... Use verbose output --color - Control colors in output [default: auto] [possible values: auto, always, never] + Control the use of color in output [possible values: auto, always, never] --native-tls Whether to load TLS certificates from the platform's native certificate store [env: UV_NATIVE_TLS=] @@ -801,7 +801,7 @@ fn help_flag_subsubcommand() { -v, --verbose... Use verbose output --color - Control colors in output [default: auto] [possible values: auto, always, never] + Control the use of color in output [possible values: auto, always, never] --native-tls Whether to load TLS certificates from the platform's native certificate store [env: UV_NATIVE_TLS=] @@ -958,7 +958,7 @@ fn help_with_global_option() { -v, --verbose... Use verbose output --color - Control colors in output [default: auto] [possible values: auto, always, never] + Control the use of color in output [possible values: auto, always, never] --native-tls Whether to load TLS certificates from the platform's native certificate store [env: UV_NATIVE_TLS=] @@ -1074,7 +1074,7 @@ fn help_with_no_pager() { -v, --verbose... Use verbose output --color - Control colors in output [default: auto] [possible values: auto, always, never] + Control the use of color in output [possible values: auto, always, never] --native-tls Whether to load TLS certificates from the platform's native certificate store [env: UV_NATIVE_TLS=] diff --git a/docs/reference/cli.md b/docs/reference/cli.md index 602c77c92..ae7230000 100644 --- a/docs/reference/cli.md +++ b/docs/reference/cli.md @@ -104,9 +104,10 @@ uv run [OPTIONS] [COMMAND]

To view the location of the cache directory, run uv cache dir.

May also be set with the UV_CACHE_DIR environment variable.

-
--color color-choice

Control colors in output

+
--color color-choice

Control the use of color in output.

+ +

By default, uv will automatically detect support for colors when writing to a terminal.

-

[default: auto]

Possible values:

    @@ -572,9 +573,10 @@ uv init [OPTIONS] [PATH]

    To view the location of the cache directory, run uv cache dir.

    May also be set with the UV_CACHE_DIR environment variable.

    -
--color color-choice

Control colors in output

+
--color color-choice

Control the use of color in output.

+ +

By default, uv will automatically detect support for colors when writing to a terminal.

-

[default: auto]

Possible values:

    @@ -766,9 +768,10 @@ uv add [OPTIONS] >

    To view the location of the cache directory, run uv cache dir.

    May also be set with the UV_CACHE_DIR environment variable.

    -
--color color-choice

Control colors in output

+
--color color-choice

Control the use of color in output.

+ +

By default, uv will automatically detect support for colors when writing to a terminal.

-

[default: auto]

Possible values:

    @@ -1132,9 +1135,10 @@ uv remove [OPTIONS] ...

    To view the location of the cache directory, run uv cache dir.

    May also be set with the UV_CACHE_DIR environment variable.

    -
--color color-choice

Control colors in output

+
--color color-choice

Control the use of color in output.

+ +

By default, uv will automatically detect support for colors when writing to a terminal.

-

[default: auto]

Possible values:

    @@ -1484,9 +1488,10 @@ uv sync [OPTIONS]

    To view the location of the cache directory, run uv cache dir.

    May also be set with the UV_CACHE_DIR environment variable.

    -
--color color-choice

Control colors in output

+
--color color-choice

Control the use of color in output.

+ +

By default, uv will automatically detect support for colors when writing to a terminal.

-

[default: auto]

Possible values:

    @@ -1873,9 +1878,10 @@ uv lock [OPTIONS]

    Equivalent to --frozen.

    May also be set with the UV_FROZEN environment variable.

    -
--color color-choice

Control colors in output

+
--color color-choice

Control the use of color in output.

+ +

By default, uv will automatically detect support for colors when writing to a terminal.

-

[default: auto]

Possible values:

    @@ -2189,9 +2195,10 @@ uv export [OPTIONS]

    To view the location of the cache directory, run uv cache dir.

    May also be set with the UV_CACHE_DIR environment variable.

    -
--color color-choice

Control colors in output

+
--color color-choice

Control the use of color in output.

+ +

By default, uv will automatically detect support for colors when writing to a terminal.

-

[default: auto]

Possible values:

    @@ -2565,9 +2572,10 @@ uv tree [OPTIONS]

    To view the location of the cache directory, run uv cache dir.

    May also be set with the UV_CACHE_DIR environment variable.

    -
--color color-choice

Control colors in output

+
--color color-choice

Control the use of color in output.

+ +

By default, uv will automatically detect support for colors when writing to a terminal.

-

[default: auto]

Possible values:

    @@ -3033,9 +3041,10 @@ uv tool run [OPTIONS] [COMMAND]

    To view the location of the cache directory, run uv cache dir.

    May also be set with the UV_CACHE_DIR environment variable.

    -
--color color-choice

Control colors in output

+
--color color-choice

Control the use of color in output.

+ +

By default, uv will automatically detect support for colors when writing to a terminal.

-

[default: auto]

Possible values:

    @@ -3354,9 +3363,10 @@ uv tool install [OPTIONS]

    To view the location of the cache directory, run uv cache dir.

    May also be set with the UV_CACHE_DIR environment variable.

    -
--color color-choice

Control colors in output

+
--color color-choice

Control the use of color in output.

+ +

By default, uv will automatically detect support for colors when writing to a terminal.

-

[default: auto]

Possible values:

    @@ -3687,9 +3697,10 @@ uv tool upgrade [OPTIONS] ...

    To view the location of the cache directory, run uv cache dir.

    May also be set with the UV_CACHE_DIR environment variable.

    -
--color color-choice

Control colors in output

+
--color color-choice

Control the use of color in output.

+ +

By default, uv will automatically detect support for colors when writing to a terminal.

-

[default: auto]

Possible values:

    @@ -3976,9 +3987,10 @@ uv tool list [OPTIONS]

    To view the location of the cache directory, run uv cache dir.

    May also be set with the UV_CACHE_DIR environment variable.

    -
--color color-choice

Control colors in output

+
--color color-choice

Control the use of color in output.

+ +

By default, uv will automatically detect support for colors when writing to a terminal.

-

[default: auto]

Possible values:

    @@ -4086,9 +4098,10 @@ uv tool uninstall [OPTIONS] ...

    To view the location of the cache directory, run uv cache dir.

    May also be set with the UV_CACHE_DIR environment variable.

    -
--color color-choice

Control colors in output

+
--color color-choice

Control the use of color in output.

+ +

By default, uv will automatically detect support for colors when writing to a terminal.

-

[default: auto]

Possible values:

    @@ -4208,9 +4221,10 @@ uv tool update-shell [OPTIONS]

    To view the location of the cache directory, run uv cache dir.

    May also be set with the UV_CACHE_DIR environment variable.

    -
--color color-choice

Control colors in output

+
--color color-choice

Control the use of color in output.

+ +

By default, uv will automatically detect support for colors when writing to a terminal.

-

[default: auto]

Possible values:

    @@ -4348,9 +4362,10 @@ uv tool dir [OPTIONS]

    To view the location of the cache directory, run uv cache dir.

    May also be set with the UV_CACHE_DIR environment variable.

    -
--color color-choice

Control colors in output

+
--color color-choice

Control the use of color in output.

+ +

By default, uv will automatically detect support for colors when writing to a terminal.

-

[default: auto]

Possible values:

    @@ -4548,9 +4563,10 @@ uv python list [OPTIONS]

    To view the location of the cache directory, run uv cache dir.

    May also be set with the UV_CACHE_DIR environment variable.

    -
--color color-choice

Control colors in output

+
--color color-choice

Control the use of color in output.

+ +

By default, uv will automatically detect support for colors when writing to a terminal.

-

[default: auto]

Possible values:

    @@ -4696,9 +4712,10 @@ uv python install [OPTIONS] [TARGETS]...

    To view the location of the cache directory, run uv cache dir.

    May also be set with the UV_CACHE_DIR environment variable.

    -
--color color-choice

Control colors in output

+
--color color-choice

Control the use of color in output.

+ +

By default, uv will automatically detect support for colors when writing to a terminal.

-

[default: auto]

Possible values:

    @@ -4863,9 +4880,10 @@ uv python find [OPTIONS] [REQUEST]

    To view the location of the cache directory, run uv cache dir.

    May also be set with the UV_CACHE_DIR environment variable.

    -
--color color-choice

Control colors in output

+
--color color-choice

Control the use of color in output.

+ +

By default, uv will automatically detect support for colors when writing to a terminal.

-

[default: auto]

Possible values:

    @@ -5008,9 +5026,10 @@ uv python pin [OPTIONS] [REQUEST]

    To view the location of the cache directory, run uv cache dir.

    May also be set with the UV_CACHE_DIR environment variable.

    -
--color color-choice

Control colors in output

+
--color color-choice

Control the use of color in output.

+ +

By default, uv will automatically detect support for colors when writing to a terminal.

-

[default: auto]

Possible values:

    @@ -5156,9 +5175,10 @@ uv python dir [OPTIONS]

    To view the location of the cache directory, run uv cache dir.

    May also be set with the UV_CACHE_DIR environment variable.

    -
--color color-choice

Control colors in output

+
--color color-choice

Control the use of color in output.

+ +

By default, uv will automatically detect support for colors when writing to a terminal.

-

[default: auto]

Possible values:

    @@ -5282,9 +5302,10 @@ uv python uninstall [OPTIONS] ...

    To view the location of the cache directory, run uv cache dir.

    May also be set with the UV_CACHE_DIR environment variable.

    -
--color color-choice

Control colors in output

+
--color color-choice

Control the use of color in output.

+ +

By default, uv will automatically detect support for colors when writing to a terminal.

-

[default: auto]

Possible values:

    @@ -5465,9 +5486,10 @@ uv pip compile [OPTIONS] ...

    To view the location of the cache directory, run uv cache dir.

    May also be set with the UV_CACHE_DIR environment variable.

    -
--color color-choice

Control colors in output

+
--color color-choice

Control the use of color in output.

+ +

By default, uv will automatically detect support for colors when writing to a terminal.

-

[default: auto]

Possible values:

    @@ -5934,9 +5956,10 @@ uv pip sync [OPTIONS] ...

    To view the location of the cache directory, run uv cache dir.

    May also be set with the UV_CACHE_DIR environment variable.

    -
--color color-choice

Control colors in output

+
--color color-choice

Control the use of color in output.

+ +

By default, uv will automatically detect support for colors when writing to a terminal.

-

[default: auto]

Possible values:

    @@ -6331,9 +6354,10 @@ uv pip install [OPTIONS] |--editable To view the location of the cache directory, run uv cache dir.

    May also be set with the UV_CACHE_DIR environment variable.

    -
--color color-choice

Control colors in output

+
--color color-choice

Control the use of color in output.

+ +

By default, uv will automatically detect support for colors when writing to a terminal.

-

[default: auto]

Possible values:

    @@ -6801,9 +6825,10 @@ uv pip uninstall [OPTIONS] >

    To view the location of the cache directory, run uv cache dir.

    May also be set with the UV_CACHE_DIR environment variable.

    -
--color color-choice

Control colors in output

+
--color color-choice

Control the use of color in output.

+ +

By default, uv will automatically detect support for colors when writing to a terminal.

-

[default: auto]

Possible values:

    @@ -6953,9 +6978,10 @@ uv pip freeze [OPTIONS]

    To view the location of the cache directory, run uv cache dir.

    May also be set with the UV_CACHE_DIR environment variable.

    -
--color color-choice

Control colors in output

+
--color color-choice

Control the use of color in output.

+ +

By default, uv will automatically detect support for colors when writing to a terminal.

-

[default: auto]

Possible values:

    @@ -7087,9 +7113,10 @@ uv pip list [OPTIONS]

    To view the location of the cache directory, run uv cache dir.

    May also be set with the UV_CACHE_DIR environment variable.

    -
--color color-choice

Control colors in output

+
--color color-choice

Control the use of color in output.

+ +

By default, uv will automatically detect support for colors when writing to a terminal.

-

[default: auto]

Possible values:

    @@ -7317,9 +7344,10 @@ uv pip show [OPTIONS] [PACKAGE]...

    To view the location of the cache directory, run uv cache dir.

    May also be set with the UV_CACHE_DIR environment variable.

    -
--color color-choice

Control colors in output

+
--color color-choice

Control the use of color in output.

+ +

By default, uv will automatically detect support for colors when writing to a terminal.

-

[default: auto]

Possible values:

    @@ -7451,9 +7479,10 @@ uv pip tree [OPTIONS]

    To view the location of the cache directory, run uv cache dir.

    May also be set with the UV_CACHE_DIR environment variable.

    -
--color color-choice

Control colors in output

+
--color color-choice

Control the use of color in output.

+ +

By default, uv will automatically detect support for colors when writing to a terminal.

-

[default: auto]

Possible values:

    @@ -7668,9 +7697,10 @@ uv pip check [OPTIONS]

    To view the location of the cache directory, run uv cache dir.

    May also be set with the UV_CACHE_DIR environment variable.

    -
--color color-choice

Control colors in output

+
--color color-choice

Control the use of color in output.

+ +

By default, uv will automatically detect support for colors when writing to a terminal.

-

[default: auto]

Possible values:

    @@ -7822,9 +7852,10 @@ uv venv [OPTIONS] [PATH]

    To view the location of the cache directory, run uv cache dir.

    May also be set with the UV_CACHE_DIR environment variable.

    -
--color color-choice

Control colors in output

+
--color color-choice

Control the use of color in output.

+ +

By default, uv will automatically detect support for colors when writing to a terminal.

-

[default: auto]

Possible values:

    @@ -8086,9 +8117,10 @@ uv build [OPTIONS] [SRC]

    To view the location of the cache directory, run uv cache dir.

    May also be set with the UV_CACHE_DIR environment variable.

    -
--color color-choice

Control colors in output

+
--color color-choice

Control the use of color in output.

+ +

By default, uv will automatically detect support for colors when writing to a terminal.

-

[default: auto]

Possible values:

    @@ -8433,9 +8465,10 @@ uv publish [OPTIONS] [FILES]...

    The index must provide one of the supported hashes (SHA-256, SHA-384, or SHA-512).

    May also be set with the UV_PUBLISH_CHECK_URL environment variable.

    -
--color color-choice

Control colors in output

+
--color color-choice

Control the use of color in output.

+ +

By default, uv will automatically detect support for colors when writing to a terminal.

-

[default: auto]

Possible values:

    @@ -8629,9 +8662,10 @@ uv cache clean [OPTIONS] [PACKAGE]...

    To view the location of the cache directory, run uv cache dir.

    May also be set with the UV_CACHE_DIR environment variable.

    -
--color color-choice

Control colors in output

+
--color color-choice

Control the use of color in output.

+ +

By default, uv will automatically detect support for colors when writing to a terminal.

-

[default: auto]

Possible values:

    @@ -8751,9 +8785,10 @@ uv cache prune [OPTIONS]

    In --ci mode, uv will prune any pre-built wheels from the cache, but retain any wheels that were built from source.

    -
--color color-choice

Control colors in output

+
--color color-choice

Control the use of color in output.

+ +

By default, uv will automatically detect support for colors when writing to a terminal.

-

[default: auto]

Possible values:

    @@ -8875,9 +8910,10 @@ uv cache dir [OPTIONS]

    To view the location of the cache directory, run uv cache dir.

    May also be set with the UV_CACHE_DIR environment variable.

    -
--color color-choice

Control colors in output

+
--color color-choice

Control the use of color in output.

+ +

By default, uv will automatically detect support for colors when writing to a terminal.

-

[default: auto]

Possible values:

    @@ -9013,9 +9049,10 @@ uv self update [OPTIONS] [TARGET_VERSION]

    To view the location of the cache directory, run uv cache dir.

    May also be set with the UV_CACHE_DIR environment variable.

    -
--color color-choice

Control colors in output

+
--color color-choice

Control the use of color in output.

+ +

By default, uv will automatically detect support for colors when writing to a terminal.

-

[default: auto]

Possible values:

    @@ -9132,9 +9169,10 @@ uv version [OPTIONS]

    To view the location of the cache directory, run uv cache dir.

    May also be set with the UV_CACHE_DIR environment variable.

    -
--color color-choice

Control colors in output

+
--color color-choice

Control the use of color in output.

+ +

By default, uv will automatically detect support for colors when writing to a terminal.

-

[default: auto]

Possible values:

    @@ -9297,9 +9335,10 @@ uv help [OPTIONS] [COMMAND]...

    To view the location of the cache directory, run uv cache dir.

    May also be set with the UV_CACHE_DIR environment variable.

    -
--color color-choice

Control colors in output

+
--color color-choice

Control the use of color in output.

+ +

By default, uv will automatically detect support for colors when writing to a terminal.

-

[default: auto]

Possible values: