-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Cargo doesn't respect --color
or CARGO_TERM_COLOR
for help text and errors from clap
#9012
Comments
The main problem here is the circular nature of this.
We can't workaround it for This would make it so let color_choice = std::env::var_os("CARGO_TERM_COLOR");
let color_choice = color_choice.and_then(|c| c.parse::<ColorChoice>().ok());
let color_choice = match color_choice {
Some(ColorChoice::CargoAuto) | None => clap::ColorChoice::Auto,
Some(ColorChoice::Always) => clap::ColorChoice::Always,
Some(ColorChoice::Never) => clap::ColorChoice::Never,
}; This intentionally ignores the errors since it isn't worth reporting at this stage. The main question is if this is worth it or not. |
--color=always
if an unknown option is encountered--color
or CARGO_TERM_COLOR
for help text and errors from clap
#13463 resolves the config side of this but leaves To handle I'd propose that we reject |
fix(cli): Control clap colors through config ### What does this PR try to resolve? Part of #9012 ### How should we test and review this PR? To accomplish this, I pivoted in how we handle `-C`. In #11029, I made the config lazily loaded. Instead, we are now reloading the config for `-C` like we do for "cargo script" and `cargo install`. If there is any regression, it will be felt by those commands as well and we can fix all together. As this is unstable, if there is a regression, the impact is less. This allowed us access to the full config for getting the color setting, rather than taking more limited approaches like checking only `CARGO_TERM_CONFIG`. ### Additional information
That sounds fair. Should we document this unfortunate truth somewhere? |
I untagged it; unsure why github closed it. |
I'm for that but unsure where it would work that it both helps the user and doesn't overwhelm them with details when they don't care (CLI parsing is a bit niche). |
The close keyword also works in commit messages 😈. |
fix(cli): Respect CARGO_TERM_COLOR in '--list' and '-Zhelp' ### What does this PR try to resolve? Similar to #9012, we aren't respecting `CARGO_TERM_COLOR` for `-Zhelp` and other places. This corrects that. ### How should we test and review this PR? #9012 was about initialization order to get the value. Here, the problem is that we don't update `Shell` with `CARGO_TERM_COLOR`. In doing this, I was concerned about keeping track of where it is safe to call `config_configure` without running it twice. To this end, I refactored `main` to make it clear that each call to `config_configure` is in a mutually exclusive path that exists immediately. ### Additional information Found this with the test for `-Zhelp` in #13461.
test(cli): Verify terminal styling ### What does this PR try to resolve? This uses a new feature from snapbox that let's us render terminal styling in SVG files. This let's us see / visualize ANSI escape codes, including in github's UI (will render images, including side-by-side images for diffs). ### How should we test and review this PR? Potential concerns - assert-rs/snapbox#257: If the snapshot file doesn't exist, you need to `SNAPSHOTS=overwrite` twice - #9012: because we narrow the enabling of colors to cargo via `CARGO_TERM_COLOR`, clap doesn't know about it and those are rendered without color - File size: `du -ch tests` reported 13MB before and after - Loss of information: this doesn't yet include links but we already weren't snapshotting these - Unconditionally turning on styling and snapshotting for it for all "ui" tests - Too many SVGs in one PR can negatively affect github's UI ### Additional information
FWIW Steps to reproduceFor some project with benches
I used my project. |
@jtmoon79 thanks for the report. That is a different issue than this. Test harness (by default it's libtest from rustc) usually provide their own way to customize console output. Those arguments could be passed after double dashes |
Problem
^title
I expect that with
--color=always
option (orCARGO_TERM_COLOR=always
environment variable) the output will contain expected ANSI escape codes.Steps
cargo build --color=always --unknown &> out.txt
out.txt
will contain the following output (without ANSI escape codes):Notes
Output of
cargo version
:The text was updated successfully, but these errors were encountered: