Skip to content

Commit 3800bff

Browse files
author
Machtan
committed
Add '--version' flag and allow version and help flags when called as 'cargo-clippy'
1 parent c687fe7 commit 3800bff

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/main.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ Usage:
118118
Common options:
119119
-h, --help Print this message
120120
--features Features to compile for the package
121+
-V, --version Print version info and exit
121122
122123
Other options are the same as `cargo rustc`.
123124
@@ -146,17 +147,22 @@ pub fn main() {
146147
if env::var("CLIPPY_DOGFOOD").map(|_| true).unwrap_or(false) {
147148
panic!("yummy");
148149
}
150+
151+
// Check for version and help flags even when invoked as 'cargo-clippy'
152+
if std::env::args().any(|a| a == "--help" || a == "-h") {
153+
show_help();
154+
return;
155+
}
156+
if std::env::args().any(|a| a == "--version" || a == "-V") {
157+
println!("{}", env!("CARGO_PKG_VERSION"));
158+
return;
159+
}
149160

150161
let dep_path = env::current_dir().expect("current dir is not readable").join("target").join("debug").join("deps");
151162

152163
if let Some("clippy") = std::env::args().nth(1).as_ref().map(AsRef::as_ref) {
153164
// this arm is executed on the initial call to `cargo clippy`
154165

155-
if std::env::args().any(|a| a == "--help" || a == "-h") {
156-
show_help();
157-
return;
158-
}
159-
160166
let manifest_path_arg = std::env::args().skip(2).find(|val| val.starts_with("--manifest-path="));
161167

162168
let mut metadata = cargo::metadata(manifest_path_arg.as_ref().map(AsRef::as_ref)).expect("could not obtain cargo metadata");

0 commit comments

Comments
 (0)