]> git.lizzy.rs Git - rust.git/commitdiff
Add '--version' flag and allow version and help flags when called as 'cargo-clippy'
authorMachtan <jako3047@gmail.com>
Tue, 8 Nov 2016 12:54:08 +0000 (13:54 +0100)
committerMachtan <jako3047@gmail.com>
Tue, 8 Nov 2016 12:54:08 +0000 (13:54 +0100)
src/main.rs

index dd7f912e4f6624fdfcabaa7bdfd51da7be3b8001..d1e9bd74c1e23db97a76994975317d99e6fea77b 100644 (file)
@@ -118,6 +118,7 @@ fn build_controller(&mut self, sess: &Session, matches: &getopts::Matches) -> dr
 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`.
 
@@ -146,17 +147,22 @@ pub fn main() {
     if env::var("CLIPPY_DOGFOOD").map(|_| true).unwrap_or(false) {
         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");
 
     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`
 
-        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 mut metadata = cargo::metadata(manifest_path_arg.as_ref().map(AsRef::as_ref)).expect("could not obtain cargo metadata");