Add '--version' flag and allow version and help flags when called as 'cargo-clippy'

This commit is contained in:
Machtan
2016-11-08 13:54:08 +01:00
parent c687fe73bc
commit 3800bff4de

View File

@@ -118,6 +118,7 @@ Usage:
Common options:
-h, --help Print this message
--features Features to compile for the package
-V, --version Print version info and exit
Other options are the same as `cargo rustc`.
@@ -147,15 +148,20 @@ pub fn main() {
panic!("yummy");
}
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) {
// this arm is executed on the initial call to `cargo clippy`
// 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");
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`
let manifest_path_arg = std::env::args().skip(2).find(|val| val.starts_with("--manifest-path="));