-
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
fix(cli): Control clap colors through config #13463
Conversation
☔ The latest upstream changes (presumably #13464) made this pull request unmergeable. Please resolve the merge conflicts. |
☔ The latest upstream changes (presumably #13409) made this pull request unmergeable. Please resolve the merge conflicts. |
This reverts commit eda1652.
0998f84
to
6e6514a
Compare
cac6f70
to
6747425
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With this patch, the color control works for CARGO_TERM_COLOR
environment variable and config.toml
. However, it doesn't work with either --color never
or --config 'term.color="never"'
, so I don't think #9012 is resolved.
Not sure if we should ship a partial solution or hold on until --color
and --config
get addressed.
pub fn cli() -> Command { | ||
pub fn cli(gctx: &GlobalContext) -> Command { | ||
// Don't let config errors get in the way of parsing arguments | ||
let term = gctx.get::<TermConfig>("term").unwrap_or_default(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue is that we sidestep without calling GlobalContext::merge_cli_args
, which GlobalContext::configure
does.
There might also be a discrepancy when we call reload_cwd()
, but that is minimal as the code path eventually calls GlobalContext::configure
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not too sure what the concern is here.
Is it that we aren't respecting --color
which you raised elsewhere and you are just calling out the relevant code?
Or is it that we aren't respecting the config from -C
to control the colors from CLI parsing? If so, that is a similar problem to --color
support (and more difficult / brittle to support)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see a reasonable way for addressing that part. We need to be able to parse the command line to get those which requires knowing what level of styling to use. We could say "parse the command line, take the result, and strip the message based on our own decision". However, |
pub fn cli() -> Command { | ||
pub fn cli(gctx: &GlobalContext) -> Command { | ||
// Don't let config errors get in the way of parsing arguments | ||
let term = gctx.get::<TermConfig>("term").unwrap_or_default(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bors r=weihanglo |
☀️ Test successful - checks-actions |
☀️ Test successful - checks-actions |
👀 Test was successful, but fast-forwarding failed: 422 Changes must be made through a pull request. |
Seems like we can leverage #13461 to test colors for this PR, right? |
Okay I didn't notice you've linked the original issue in that PR. |
Update cargo 16 commits in 194a60b2952bd5d12ba15dd2577a97eed7d3c587..8964c8ccff6e420e2a38b8696d178d69fab84d9d 2024-02-21 01:53:45 +0000 to 2024-02-27 19:22:46 +0000 - feat: Add "-Zpublic-dependency" for public-dependency feature. (rust-lang/cargo#13340) - Stabilize global cache data tracking. (rust-lang/cargo#13492) - chore: bump baseline version requirement of sub crates (rust-lang/cargo#13494) - fix(doctest): search native libs in build script outputs (rust-lang/cargo#13490) - chore: fixed a typo(two->too) (rust-lang/cargo#13489) - test: relax help text assertion (rust-lang/cargo#13488) - refactor: clean up for `GlobalContext` rename (rust-lang/cargo#13486) - test(cli): Verify terminal styling (rust-lang/cargo#13461) - fix(cli): Respect CARGO_TERM_COLOR in '--list' and '-Zhelp' (rust-lang/cargo#13479) - Error messages when collecting workspace members now mention the workspace root location (rust-lang/cargo#13480) - fix(add): Improve error when adding registry packages while vendored (rust-lang/cargo#13281) - [docs]:Add missing jump links (rust-lang/cargo#13478) - Add global_cache_tracker stability tests. (rust-lang/cargo#13467) - fix(cli): Control clap colors through config (rust-lang/cargo#13463) - chore: remove the unused function (rust-lang/cargo#13472) - Fix missing brackets (rust-lang/cargo#13470)
Update cargo 16 commits in 194a60b2952bd5d12ba15dd2577a97eed7d3c587..8964c8ccff6e420e2a38b8696d178d69fab84d9d 2024-02-21 01:53:45 +0000 to 2024-02-27 19:22:46 +0000 - feat: Add "-Zpublic-dependency" for public-dependency feature. (rust-lang/cargo#13340) - Stabilize global cache data tracking. (rust-lang/cargo#13492) - chore: bump baseline version requirement of sub crates (rust-lang/cargo#13494) - fix(doctest): search native libs in build script outputs (rust-lang/cargo#13490) - chore: fixed a typo(two->too) (rust-lang/cargo#13489) - test: relax help text assertion (rust-lang/cargo#13488) - refactor: clean up for `GlobalContext` rename (rust-lang/cargo#13486) - test(cli): Verify terminal styling (rust-lang/cargo#13461) - fix(cli): Respect CARGO_TERM_COLOR in '--list' and '-Zhelp' (rust-lang/cargo#13479) - Error messages when collecting workspace members now mention the workspace root location (rust-lang/cargo#13480) - fix(add): Improve error when adding registry packages while vendored (rust-lang/cargo#13281) - [docs]:Add missing jump links (rust-lang/cargo#13478) - Add global_cache_tracker stability tests. (rust-lang/cargo#13467) - fix(cli): Control clap colors through config (rust-lang/cargo#13463) - chore: remove the unused function (rust-lang/cargo#13472) - Fix missing brackets (rust-lang/cargo#13470)
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" andcargo 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 onlyCARGO_TERM_CONFIG
.Additional information