Skip to content

Commit 068bcad

Browse files
committed
rustfmt-format-diff: Use logging macros instead of "-v" option.
1 parent c12b4e9 commit 068bcad

File tree

1 file changed

+11
-20
lines changed

1 file changed

+11
-20
lines changed

src/bin/rustfmt-format-diff.rs

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414

1515
#![deny(warnings)]
1616

17+
extern crate env_logger;
1718
extern crate getopts;
19+
#[macro_use]
20+
extern crate log;
1821
extern crate regex;
1922
extern crate serde;
2023
#[macro_use]
@@ -79,9 +82,10 @@ impl From<io::Error> for FormatDiffError {
7982
}
8083

8184
fn main() {
85+
let _ = env_logger::init();
86+
8287
let mut opts = getopts::Options::new();
8388
opts.optflag("h", "help", "show this message");
84-
opts.optflag("v", "verbose", "use verbose output");
8589
opts.optopt(
8690
"p",
8791
"skip-prefix",
@@ -115,43 +119,30 @@ fn run(opts: &getopts::Options) -> Result<(), FormatDiffError> {
115119
return Ok(());
116120
}
117121

118-
let verbose = matches.opt_present("v");
119-
120122
let filter = matches
121123
.opt_str("f")
122124
.unwrap_or_else(|| DEFAULT_PATTERN.into());
123125

124-
125126
let skip_prefix = matches
126127
.opt_str("p")
127128
.and_then(|p| p.parse::<u32>().ok())
128129
.unwrap_or(0);
129130

130131
let (files, ranges) = scan_diff(io::stdin(), skip_prefix, &filter)?;
131132

132-
run_rustfmt(&files, &ranges, verbose)
133+
run_rustfmt(&files, &ranges)
133134
}
134135

135-
fn run_rustfmt(
136-
files: &HashSet<String>,
137-
ranges: &[Range],
138-
verbose: bool,
139-
) -> Result<(), FormatDiffError> {
136+
fn run_rustfmt(files: &HashSet<String>, ranges: &[Range]) -> Result<(), FormatDiffError> {
140137
if files.is_empty() || ranges.is_empty() {
141-
if verbose {
142-
println!("No files to format found");
143-
}
138+
debug!("No files to format found");
144139
return Ok(());
145140
}
146141

147142
let ranges_as_json = json::to_string(ranges).unwrap();
148-
if verbose {
149-
print!("rustfmt");
150-
for file in files {
151-
print!(" {:?}", file);
152-
}
153-
print!(" --file-lines {:?}", ranges_as_json);
154-
}
143+
144+
debug!("Files: {:?}", files);
145+
debug!("Ranges: {:?}", ranges);
155146

156147
let exit_status = process::Command::new("rustfmt")
157148
.args(files)

0 commit comments

Comments
 (0)