-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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 colored help to be consistent with Cargo #11495
Conversation
r? @giraffate (rustbot has picked a reviewer for you, use r? to override) |
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.
Blocker: This doesn't work when piping the output to a file:
LD_LIBRARY_PATH=$(rustc --print=sysroot)/lib ./target/debug/cargo-clippy --help > test
results in:
Checks a package to catch common mistakes and improve your Rust code.
�[32m�[1mUsage�[39m�[22m:
�[36m�[1mcargo clippy�[39m�[22m �[36m[OPTIONS] [--] [<ARGS>...]�[39m
�[32m�[1mCommon options:�[39m�[22m
�[36m�[1m--no-deps�[39m�[22m Run Clippy only on the given crate, without linting the dependencies
�[36m�[1m--fix�[39m�[22m Automatically apply lint suggestions. This flag implies �[36m--no-deps�[39m and �[36m--all-targets�[39m
�[36m�[1m-h, --help�[39m�[22m Print this message
�[36m�[1m-V, --version�[39m�[22m Print version info and exit
�[36m�[1m--explain [LINT]�[39m�[22m Print the documentation for a given lint
See all options with �[36m�[1mcargo check --help�[39m�[22m.
�[32m�[1mAllowing / Denying lints�[39m�[22m
To allow or deny a lint from the command line you can use �[36m�[1mcargo clippy --�[39m�[22m with:
�[36m�[1m-W�[39m�[22m / �[36m�[1m--warn�[39m�[22m �[36m[LINT]�[39m Set lint warnings
�[36m�[1m-A�[39m�[22m / �[36m�[1m--allow�[39m�[22m �[36m[LINT]�[39m Set lint allowed
�[36m�[1m-D�[39m�[22m / �[36m�[1m--deny�[39m�[22m �[36m[LINT]�[39m Set lint denied
�[36m�[1m-F�[39m�[22m / �[36m�[1m--forbid�[39m�[22m �[36m[LINT]�[39m Set lint forbidden
You can use tool lints to allow or deny lints from your code, e.g.:
�[33m�[1m#[allow(clippy::needless_lifetimes)]�[39m�[22m
OK, this new approach fixes Philipp's comment but introduces kind of a lot of bloat. On the original PR, this bloat isn't there because |
Should we use |
Adding Also note that, if we use |
Sadly the clunky syntax is probably there to stay for backwards compat... |
There's probably a way to maintain this backwards compatibility while also providing a better solution. |
As an alternative to pulling in all of clap, you can use the |
The current commit also checks if we're on a terminal and adjusts the output to that information. Pulling a dependency just to avoid an |
Help output performance isn't the biggest deal and the dependency helps with (1) only having one instance of the help to avoid subtle issues with them being out of sync and (2) it covers more situations (NOCOLOR, CLI_COLOR, legacy windows, etc). |
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.
You found a bug in ignored_unit_patterns
: Needs an external macro check.
The lint uses |
src/main.rs
Outdated
<cyan,bold>--fix</> Automatically apply lint suggestions. This flag implies <cyan>--no-deps</> and <cyan>--all-targets</> | ||
<cyan,bold>-h</>, <cyan,bold>--help</> Print this message | ||
<cyan,bold>-V</>, <cyan,bold>--version</> Print version info and exit | ||
<cyan,bold>--explain [LINT]</> Print the documentation for a given lint |
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.
<cyan,bold>--explain [LINT]</> Print the documentation for a given lint | |
<cyan,bold>--explain [LINT]</> Print the documentation for a given lint |
2f1f8df
to
6ed217f
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.
Still some work to be done on the clippy-driver help message.
r? @flip1995 |
Please fix the alignment of the Optionally address this comment: #11495 (comment) |
src/driver.rs
Outdated
#[must_use] | ||
fn help_message() -> &'static str { | ||
color_print::cstr!( | ||
"Checks a package to catch common mistakes and improve your Rust code. Run <cyan>clippy-driver</> with the same arguments you use for <cyan>rustc</> |
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.
"Checks a package to catch common mistakes and improve your Rust code. Run <cyan>clippy-driver</> with the same arguments you use for <cyan>rustc</> | |
"Checks a file to catch common mistakes and improve your Rust code. | |
Run <cyan>clippy-driver</> with the same arguments you use for <cyan>rustc</> |
Truly a sad cowboy moment. |
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.
Thanks! r=me after squashing the commits 🚀
efe28ee
to
6ad218c
Compare
@bors r=flip1995 |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
On rust-lang/cargo#12578, a new colored help message format was introduced. This PR introduces the same styling from that
cargo help
message to ourcargo clippy --help
message.More information is provided in the original PR, fixes #11482. The perfect reviewing process would be that the reviewer installs this branch and checks for themselves, but here are some screenshots, there are some more screenshots in the original issue.
(Note that the actual text may change in the actual commit, that screenshot is just to test the colors).
Also note that the
color-print
version should always be synced with Cargo'scolor-print
version to avoid increasing build times in the rust-lang/rust repo.changelog:Add colors to the
cargo clippy --help
output 🎉.