]> git.lizzy.rs Git - rust.git/commitdiff
Do not run cargo fmt if there are unnecessary arguments
authorSeiichi Uchida <topecongiro@localhost.localdomain>
Mon, 19 Jun 2017 14:39:59 +0000 (23:39 +0900)
committerSeiichi Uchida <topecongiro@localhost.localdomain>
Mon, 19 Jun 2017 14:39:59 +0000 (23:39 +0900)
src/bin/cargo-fmt.rs

index 93348b8299669870b45889105286f7c59838852c..c8202eb7e41bd09a77ec05c6b3f2ca50b2e95025 100644 (file)
@@ -50,6 +50,16 @@ fn execute() -> i32 {
     );
     opts.optflag("", "all", "format all packages (only usable in workspaces)");
 
+    // If there is any invalid argument passed to `cargo fmt`, return without formatting.
+    if let Some(arg) = env::args()
+        .skip(2)
+        .take_while(|a| a != "--")
+        .find(|a| !a.starts_with('-'))
+    {
+        print_usage(&opts, &format!("Invalid argument: `{}`.", arg));
+        return failure;
+    }
+
     let matches = match opts.parse(env::args().skip(1).take_while(|a| a != "--")) {
         Ok(m) => m,
         Err(e) => {