Do not run cargo fmt if there are unnecessary arguments

This commit is contained in:
Seiichi Uchida 2017-06-19 23:39:59 +09:00
parent a87a4450aa
commit 53202b4029

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