extern crate rustfmt_nightly as rustfmt;
use std::env;
+use std::io::stdout;
use std::path::{Path, PathBuf};
use std::process::Command;
use std::str::FromStr;
use getopts::{Matches, Options};
-use rustfmt::{format_and_emit_report, load_config, Input};
+use rustfmt::{load_config, CliOptions, Input, Session};
fn prune_files(files: Vec<&str>) -> Vec<&str> {
let prefixes: Vec<_> = files
}
fn fmt_files(files: &[&str]) -> i32 {
- let (config, _) = load_config(Some(Path::new(".")), None).expect("couldn't load config");
+ let (config, _) =
+ load_config::<NullOptions>(Some(Path::new(".")), None).expect("couldn't load config");
let mut exit_code = 0;
+ let mut out = stdout();
+ let mut session = Session::new(config, Some(&mut out));
for file in files {
- let summary = format_and_emit_report(Input::File(PathBuf::from(file)), &config).unwrap();
- if !summary.has_no_errors() {
+ let report = session.format(Input::File(PathBuf::from(file))).unwrap();
+ if report.has_warnings() {
+ eprintln!("{}", report);
+ }
+ if !session.has_no_errors() {
exit_code = 1;
}
}
exit_code
}
+struct NullOptions;
+
+impl CliOptions for NullOptions {
+ fn apply_to(self, _: &mut rustfmt::Config) {
+ unreachable!();
+ }
+ fn config_path(&self) -> Option<&Path> {
+ unreachable!();
+ }
+}
+
fn uncommitted_files() -> Vec<String> {
let mut cmd = Command::new("git");
cmd.arg("ls-files");