Add '--version' flag and allow version and help flags when called as 'cargo-clippy'
This commit is contained in:
16
src/main.rs
16
src/main.rs
@@ -118,6 +118,7 @@ Usage:
|
|||||||
Common options:
|
Common options:
|
||||||
-h, --help Print this message
|
-h, --help Print this message
|
||||||
--features Features to compile for the package
|
--features Features to compile for the package
|
||||||
|
-V, --version Print version info and exit
|
||||||
|
|
||||||
Other options are the same as `cargo rustc`.
|
Other options are the same as `cargo rustc`.
|
||||||
|
|
||||||
@@ -146,17 +147,22 @@ pub fn main() {
|
|||||||
if env::var("CLIPPY_DOGFOOD").map(|_| true).unwrap_or(false) {
|
if env::var("CLIPPY_DOGFOOD").map(|_| true).unwrap_or(false) {
|
||||||
panic!("yummy");
|
panic!("yummy");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check for version and help flags even when invoked as 'cargo-clippy'
|
||||||
|
if std::env::args().any(|a| a == "--help" || a == "-h") {
|
||||||
|
show_help();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if std::env::args().any(|a| a == "--version" || a == "-V") {
|
||||||
|
println!("{}", env!("CARGO_PKG_VERSION"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let dep_path = env::current_dir().expect("current dir is not readable").join("target").join("debug").join("deps");
|
let dep_path = env::current_dir().expect("current dir is not readable").join("target").join("debug").join("deps");
|
||||||
|
|
||||||
if let Some("clippy") = std::env::args().nth(1).as_ref().map(AsRef::as_ref) {
|
if let Some("clippy") = std::env::args().nth(1).as_ref().map(AsRef::as_ref) {
|
||||||
// this arm is executed on the initial call to `cargo clippy`
|
// this arm is executed on the initial call to `cargo clippy`
|
||||||
|
|
||||||
if std::env::args().any(|a| a == "--help" || a == "-h") {
|
|
||||||
show_help();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let manifest_path_arg = std::env::args().skip(2).find(|val| val.starts_with("--manifest-path="));
|
let manifest_path_arg = std::env::args().skip(2).find(|val| val.starts_with("--manifest-path="));
|
||||||
|
|
||||||
let mut metadata = cargo::metadata(manifest_path_arg.as_ref().map(AsRef::as_ref)).expect("could not obtain cargo metadata");
|
let mut metadata = cargo::metadata(manifest_path_arg.as_ref().map(AsRef::as_ref)).expect("could not obtain cargo metadata");
|
||||||
|
|||||||
Reference in New Issue
Block a user