-
-
Notifications
You must be signed in to change notification settings - Fork 80
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
Add --color
setting to CLI.
#721
Conversation
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.
Looks great so far!
Re: testing, could you add some tests of the various --color
options and env var settings into a new file in the tests
directory? You can use existing tests like the ones in rustdoc_edge_cases.rs
as inspiration for how to pass arguments, manipulate env vars, and check stdout / stderr to ensure the output includes / avoids color codes, as expected.
Ideally, we'd have both a "all lints passed" and a "some lints failed" run of cargo-semver-checks
, and the test would ensure each of them produces the appropriate output (non-)colorization based on the env vars and CLI flags, with the appropriate precedence between them.
Tangential comment. Please disregard since it's only for future note. The recommended SOTA color-related logic is to use the rust-cli/anstyle crates. |
messed up my rebase and left in lazy_static
Co-authored-by: Predrag Gruevski <2348618+obi1kenobi@users.noreply.github.com>
Added some tests in the |
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.
Nicely done, thank you! I'm going to slip in a couple of tiny tweaks for a couple of nitpicks I had, and mark for merge as soon as CI passes.
Also, this explanation was great! It was very useful context that helped me understand the pull request much more easily. Thanks for putting it together! |
Fixes #719
There is already code to recognize the
CARGO_TERM_COLOR
environment variable for setting color policy inGlobalConfig::new()
. This PR makes it so that the--color=...
flag takes precedence over the env var, but if the CLI flag is not set, then the env var still applies if it is set.I'm not super happy with needing the
if let
block that comes withset_color_choice
in order to not overwrite the env var - I'd definitely be willing to refactor the env var detection into a different function or make some other change.I wasn't sure if tests were necessary/how to test this. If you want tests, let me know and I can add them.