]> git.lizzy.rs Git - rust.git/commitdiff
Allow '--package <package>'
authortopecongiro <seuchida@gmail.com>
Mon, 27 Nov 2017 10:29:26 +0000 (19:29 +0900)
committertopecongiro <seuchida@gmail.com>
Mon, 27 Nov 2017 10:29:26 +0000 (19:29 +0900)
src/bin/cargo-fmt.rs

index fb1a13d07f7c9850edc3e883a43eac8625ec6649..33e7db7adcd7036dda8df1436bbf4a7dc222ae0b 100644 (file)
@@ -52,13 +52,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_to_stderr(&opts, &format!("Invalid argument: `{}`.", arg));
-        return failure;
+    let mut is_package_arg = false;
+    for arg in env::args().skip(2).take_while(|a| a != "--") {
+        if arg.starts_with("-") {
+            is_package_arg = arg.starts_with("--package");
+        } else if !is_package_arg {
+            print_usage_to_stderr(&opts, &format!("Invalid argument: `{}`.", arg));
+            return failure;
+        } else {
+            is_package_arg = false;
+        }
     }
 
     let matches = match opts.parse(env::args().skip(1).take_while(|a| a != "--")) {