]> git.lizzy.rs Git - rust.git/commitdiff
Merge pull request #1733 from topecongiro/cargo-fmt
authorNick Cameron <nrc@ncameron.org>
Tue, 20 Jun 2017 00:28:36 +0000 (12:28 +1200)
committerGitHub <noreply@github.com>
Tue, 20 Jun 2017 00:28:36 +0000 (12:28 +1200)
Do not run cargo fmt if there are unnecessary arguments

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) => {