rustfmt-format-diff: Use logging macros instead of "-v" option.

This commit is contained in:
Emilio Cobos Álvarez 2017-07-31 09:38:24 +01:00
parent c12b4e9031
commit 068bcad880
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C

View file

@ -14,7 +14,10 @@
#![deny(warnings)]
extern crate env_logger;
extern crate getopts;
#[macro_use]
extern crate log;
extern crate regex;
extern crate serde;
#[macro_use]
@ -79,9 +82,10 @@ impl From<io::Error> for FormatDiffError {
}
fn main() {
let _ = env_logger::init();
let mut opts = getopts::Options::new();
opts.optflag("h", "help", "show this message");
opts.optflag("v", "verbose", "use verbose output");
opts.optopt(
"p",
"skip-prefix",
@ -115,13 +119,10 @@ fn run(opts: &getopts::Options) -> Result<(), FormatDiffError> {
return Ok(());
}
let verbose = matches.opt_present("v");
let filter = matches
.opt_str("f")
.unwrap_or_else(|| DEFAULT_PATTERN.into());
let skip_prefix = matches
.opt_str("p")
.and_then(|p| p.parse::<u32>().ok())
@ -129,29 +130,19 @@ fn run(opts: &getopts::Options) -> Result<(), FormatDiffError> {
let (files, ranges) = scan_diff(io::stdin(), skip_prefix, &filter)?;
run_rustfmt(&files, &ranges, verbose)
run_rustfmt(&files, &ranges)
}
fn run_rustfmt(
files: &HashSet<String>,
ranges: &[Range],
verbose: bool,
) -> Result<(), FormatDiffError> {
fn run_rustfmt(files: &HashSet<String>, ranges: &[Range]) -> Result<(), FormatDiffError> {
if files.is_empty() || ranges.is_empty() {
if verbose {
println!("No files to format found");
}
debug!("No files to format found");
return Ok(());
}
let ranges_as_json = json::to_string(ranges).unwrap();
if verbose {
print!("rustfmt");
for file in files {
print!(" {:?}", file);
}
print!(" --file-lines {:?}", ranges_as_json);
}
debug!("Files: {:?}", files);
debug!("Ranges: {:?}", ranges);
let exit_status = process::Command::new("rustfmt")
.args(files)