let mut opts = getopts::Options::new();
opts.optflag("h", "help", "show this message");
- let matches = match opts.parse(env::args().skip(1)) {
+ let matches = match opts.parse(env::args().skip(1).take_while(|a| a != "--")) {
Ok(m) => m,
Err(e) => {
print_usage(&opts, &e.to_string());
fn print_usage(opts: &Options, reason: &str) {
let msg = format!("{}\nusage: cargo fmt [options]", reason);
- println!("{}\nThis utility formats all bin and lib files of the current crate using rustfmt.",
+ println!("{}\nThis utility formats all bin and lib files of the current crate using rustfmt. \
+ Arguments after `--` are passed to rustfmt.",
opts.usage(&msg));
}
.map(|t| t.path)
.collect();
- format_files(&files).unwrap_or_else(|e| print_usage(opts, &e.to_string()));
+ format_files(&files, &get_fmt_args()).unwrap_or_else(|e| print_usage(opts, &e.to_string()));
+}
+
+fn get_fmt_args() -> Vec<String> {
+ // All arguments after -- are passed to rustfmt
+ env::args().skip_while(|a| a != "--").skip(1).collect()
}
#[derive(Debug)]
}
}
-fn format_files(files: &Vec<PathBuf>) -> Result<(), std::io::Error> {
+fn format_files(files: &Vec<PathBuf>, fmt_args: &Vec<String>) -> Result<(), std::io::Error> {
let mut command = try!(Command::new("rustfmt")
- .arg("--write-mode=overwrite")
.args(files)
+ .args(fmt_args)
.spawn());
try!(command.wait());