Skip to content

Commit a5b647f

Browse files
committed
Allow '--package <package>'
1 parent bf87d9b commit a5b647f

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/bin/cargo-fmt.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,16 @@ fn execute() -> i32 {
5252
opts.optflag("", "all", "format all packages (only usable in workspaces)");
5353

5454
// If there is any invalid argument passed to `cargo fmt`, return without formatting.
55-
if let Some(arg) = env::args()
56-
.skip(2)
57-
.take_while(|a| a != "--")
58-
.find(|a| !a.starts_with('-'))
59-
{
60-
print_usage_to_stderr(&opts, &format!("Invalid argument: `{}`.", arg));
61-
return failure;
55+
let mut is_package_arg = false;
56+
for arg in env::args().skip(2).take_while(|a| a != "--") {
57+
if arg.starts_with("-") {
58+
is_package_arg = arg.starts_with("--package");
59+
} else if !is_package_arg {
60+
print_usage_to_stderr(&opts, &format!("Invalid argument: `{}`.", arg));
61+
return failure;
62+
} else {
63+
is_package_arg = false;
64+
}
6265
}
6366

6467
let matches = match opts.parse(env::args().skip(1).take_while(|a| a != "--")) {

0 commit comments

Comments
 (0)