]> git.lizzy.rs Git - rust.git/commitdiff
Drop only the first occurrence of `fmt` while preparing CLI arguments
authorIvan Veselov <veselov@gmail.com>
Tue, 21 May 2019 15:33:51 +0000 (16:33 +0100)
committerIvan Veselov <veselov@gmail.com>
Tue, 21 May 2019 15:36:53 +0000 (16:36 +0100)
src/cargo-fmt/main.rs

index a265347e03371367824b0daf5496defd1e4e5fcf..3c4d1c08b0867d2103260bdab5862de28f4be9c7 100644 (file)
@@ -62,7 +62,16 @@ fn main() {
 
 fn execute() -> i32 {
     // Drop extra `fmt` argument provided by `cargo`.
-    let args = env::args().filter(|x| x != "fmt");
+    let mut found_fmt = false;
+    let args = env::args().filter(|x| {
+        if found_fmt {
+            true
+        } else {
+            found_fmt = x == "fmt";
+            x != "fmt"
+        }
+    });
+
     let opts = Opts::from_iter(args);
 
     let verbosity = match (opts.verbose, opts.quiet) {