Auto merge of #11495 - blyxyas:help_message_reformat, r=flip1995
Add colored help to be consistent with Cargo 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 our `cargo 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's `color-print` version to avoid increasing build times in the rust-lang/rust repo. changelog:Add colors to the `cargo clippy --help` output 🎉.
This commit is contained in:
commit
78ddc8d17d
@ -25,6 +25,8 @@ clippy_lints = { path = "clippy_lints" }
|
||||
rustc_tools_util = "0.3.0"
|
||||
tempfile = { version = "3.2", optional = true }
|
||||
termize = "0.1"
|
||||
color-print = "0.3.4" # Sync version with Cargo
|
||||
anstream = "0.5.0"
|
||||
|
||||
[dev-dependencies]
|
||||
ui_test = "0.20"
|
||||
|
@ -26,6 +26,8 @@ use std::ops::Deref;
|
||||
use std::path::Path;
|
||||
use std::process::exit;
|
||||
|
||||
use anstream::println;
|
||||
|
||||
/// If a command-line option matches `find_arg`, then apply the predicate `pred` on its value. If
|
||||
/// true, then return it. The parameter is assumed to be either `--arg=value` or `--arg value`.
|
||||
fn arg_value<'a, T: Deref<Target = str>>(
|
||||
@ -162,39 +164,15 @@ impl rustc_driver::Callbacks for ClippyCallbacks {
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::ignored_unit_patterns)]
|
||||
fn display_help() {
|
||||
println!(
|
||||
"\
|
||||
Checks a package to catch common mistakes and improve your Rust code.
|
||||
|
||||
Usage:
|
||||
cargo clippy [options] [--] [<opts>...]
|
||||
|
||||
Common options:
|
||||
-h, --help Print this message
|
||||
--rustc Pass all args to rustc
|
||||
-V, --version Print version info and exit
|
||||
|
||||
For the other options see `cargo check --help`.
|
||||
|
||||
To allow or deny a lint from the command line you can use `cargo clippy --`
|
||||
with:
|
||||
|
||||
-W --warn OPT Set lint warnings
|
||||
-A --allow OPT Set lint allowed
|
||||
-D --deny OPT Set lint denied
|
||||
-F --forbid OPT Set lint forbidden
|
||||
|
||||
You can use tool lints to allow or deny lints from your code, eg.:
|
||||
|
||||
#[allow(clippy::needless_lifetimes)]
|
||||
"
|
||||
);
|
||||
println!("{}", help_message());
|
||||
}
|
||||
|
||||
const BUG_REPORT_URL: &str = "https://github.com/rust-lang/rust-clippy/issues/new?template=ice.yml";
|
||||
|
||||
#[allow(clippy::too_many_lines)]
|
||||
#[allow(clippy::ignored_unit_patterns)]
|
||||
pub fn main() {
|
||||
let handler = EarlyErrorHandler::new(ErrorOutputType::default());
|
||||
|
||||
@ -236,6 +214,7 @@ pub fn main() {
|
||||
|
||||
if orig_args.iter().any(|a| a == "--version" || a == "-V") {
|
||||
let version_info = rustc_tools_util::get_version_info!();
|
||||
|
||||
println!("{version_info}");
|
||||
exit(0);
|
||||
}
|
||||
@ -292,3 +271,25 @@ pub fn main() {
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
fn help_message() -> &'static str {
|
||||
color_print::cstr!(
|
||||
"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</>
|
||||
|
||||
<green,bold>Usage</>:
|
||||
<cyan,bold>clippy-driver</> <cyan>[OPTIONS] INPUT</>
|
||||
|
||||
<green,bold>Common options:</>
|
||||
<cyan,bold>-h</>, <cyan,bold>--help</> Print this message
|
||||
<cyan,bold>-V</>, <cyan,bold>--version</> Print version info and exit
|
||||
<cyan,bold>--rustc</> Pass all arguments to <cyan>rustc</>
|
||||
|
||||
<green,bold>Allowing / Denying lints</>
|
||||
You can use tool lints to allow or deny lints from your code, e.g.:
|
||||
|
||||
<yellow,bold>#[allow(clippy::needless_lifetimes)]</>
|
||||
"
|
||||
)
|
||||
}
|
||||
|
63
src/main.rs
63
src/main.rs
@ -6,37 +6,14 @@ use std::env;
|
||||
use std::path::PathBuf;
|
||||
use std::process::{self, Command};
|
||||
|
||||
const CARGO_CLIPPY_HELP: &str = "Checks a package to catch common mistakes and improve your Rust code.
|
||||
|
||||
Usage:
|
||||
cargo clippy [options] [--] [<opts>...]
|
||||
|
||||
Common options:
|
||||
--no-deps Run Clippy only on the given crate, without linting the dependencies
|
||||
--fix Automatically apply lint suggestions. This flag implies `--no-deps` and `--all-targets`
|
||||
-h, --help Print this message
|
||||
-V, --version Print version info and exit
|
||||
--explain LINT Print the documentation for a given lint
|
||||
|
||||
For the other options see `cargo check --help`.
|
||||
|
||||
To allow or deny a lint from the command line you can use `cargo clippy --`
|
||||
with:
|
||||
|
||||
-W --warn OPT Set lint warnings
|
||||
-A --allow OPT Set lint allowed
|
||||
-D --deny OPT Set lint denied
|
||||
-F --forbid OPT Set lint forbidden
|
||||
|
||||
You can use tool lints to allow or deny lints from your code, e.g.:
|
||||
|
||||
#[allow(clippy::needless_lifetimes)]
|
||||
";
|
||||
use anstream::println;
|
||||
|
||||
#[allow(clippy::ignored_unit_patterns)]
|
||||
fn show_help() {
|
||||
println!("{CARGO_CLIPPY_HELP}");
|
||||
println!("{}", help_message());
|
||||
}
|
||||
|
||||
#[allow(clippy::ignored_unit_patterns)]
|
||||
fn show_version() {
|
||||
let version_info = rustc_tools_util::get_version_info!();
|
||||
println!("{version_info}");
|
||||
@ -168,6 +145,38 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn help_message() -> &'static str {
|
||||
color_print::cstr!(
|
||||
"Checks a package to catch common mistakes and improve your Rust code.
|
||||
|
||||
<green,bold>Usage</>:
|
||||
<cyan,bold>cargo clippy</> <cyan>[OPTIONS] [--] [<<ARGS>>...]</>
|
||||
|
||||
<green,bold>Common options:</>
|
||||
<cyan,bold>--no-deps</> Run Clippy only on the given crate, without linting the dependencies
|
||||
<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
|
||||
|
||||
See all options with <cyan,bold>cargo check --help</>.
|
||||
|
||||
<green,bold>Allowing / Denying lints</>
|
||||
|
||||
To allow or deny a lint from the command line you can use <cyan,bold>cargo clippy --</> with:
|
||||
|
||||
<cyan,bold>-W</> / <cyan,bold>--warn</> <cyan>[LINT]</> Set lint warnings
|
||||
<cyan,bold>-A</> / <cyan,bold>--allow</> <cyan>[LINT]</> Set lint allowed
|
||||
<cyan,bold>-D</> / <cyan,bold>--deny</> <cyan>[LINT]</> Set lint denied
|
||||
<cyan,bold>-F</> / <cyan,bold>--forbid</> <cyan>[LINT]</> Set lint forbidden
|
||||
|
||||
You can use tool lints to allow or deny lints from your code, e.g.:
|
||||
|
||||
<yellow,bold>#[allow(clippy::needless_lifetimes)]</>
|
||||
"
|
||||
)
|
||||
}
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::ClippyCmd;
|
||||
|
Loading…
x
Reference in New Issue
Block a user