diff --git a/src/bin/rustfmt.rs b/src/bin/rustfmt.rs index de906729b31..b90cdb3d3ca 100644 --- a/src/bin/rustfmt.rs +++ b/src/bin/rustfmt.rs @@ -29,8 +29,8 @@ use getopts::Options; /// Rustfmt operations. enum Operation { - /// Format a file and its child modules. - Format(PathBuf, WriteMode), + /// Format files and their child modules. + Format(Vec, WriteMode), /// Print the help message. Help, /// Print detailed configuration help. @@ -114,16 +114,20 @@ fn execute() -> i32 { run_from_stdin(input, write_mode, &config); 0 } - Operation::Format(file, write_mode) => { - let config = match lookup_and_read_project_file(&file) { - Ok((path, toml)) => { - println!("Using rustfmt config file: {}", path.display()); - Config::from_toml(&toml) - } - Err(_) => Default::default(), - }; + Operation::Format(files, write_mode) => { + for file in files { + let config = match lookup_and_read_project_file(&file) { + Ok((path, toml)) => { + println!("Using rustfmt config file {} for {}", + path.display(), + file.display()); + Config::from_toml(&toml) + } + Err(_) => Default::default(), + }; - run(&file, write_mode, &config); + run(&file, write_mode, &config); + } 0 } } @@ -144,7 +148,7 @@ fn main() { } fn print_usage(opts: &Options, reason: &str) { - let reason = format!("{}\nusage: {} [options] ", + let reason = format!("{}\nusage: {} [options] ...", reason, env::current_exe().unwrap().display()); println!("{}", opts.usage(&reason)); @@ -189,5 +193,7 @@ fn determine_operation(opts: &Options, args: I) -> Operation None => WriteMode::Replace, }; - Operation::Format(PathBuf::from(&matches.free[0]), write_mode) + let files: Vec<_> = matches.free.iter().map(|a| PathBuf::from(a)).collect(); + + Operation::Format(files, write_mode) }