Skip to content

Commit

Permalink
Address review concerns
Browse files Browse the repository at this point in the history
  • Loading branch information
Johann committed Nov 3, 2015
1 parent fcc62cb commit 154e20a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 21 deletions.
21 changes: 4 additions & 17 deletions src/bin/rustfmt.rs
Expand Up @@ -77,8 +77,8 @@ fn execute() -> i32 {
opts.optflag("h", "help", "show this message");
opts.optopt("",
"write-mode",
"mode to write in",
"[replace|overwrite|display|plain|diff|coverage]");
"mode to write in (not usable when piping from stdin)",
"[replace|overwrite|display|diff|coverage]");

let operation = determine_operation(&opts, env::args().skip(1));

Expand Down Expand Up @@ -153,28 +153,15 @@ fn determine_operation<I>(opts: &Options, args: I) -> Operation
}

// if no file argument is supplied, read from stdin
if matches.free.len() != 1 {

// make sure the write mode is plain or not set
// (the other options would require a file)
match matches.opt_str("write-mode") {
Some(mode) => {
match mode.parse() {
Ok(WriteMode::Plain) => (),
_ => return Operation::InvalidInput("Using stdin requires write-mode to be \
plain"
.into()),
}
}
_ => (),
}
if matches.free.len() == 0 {

let mut buffer = String::new();
match io::stdin().read_to_string(&mut buffer) {
Ok(..) => (),
Err(e) => return Operation::InvalidInput(e.to_string()),
}

// WriteMode is always plain for Stdin
return Operation::Stdin(buffer, WriteMode::Plain);
}

Expand Down
8 changes: 4 additions & 4 deletions src/filemap.rs
Expand Up @@ -102,14 +102,14 @@ pub fn write_file(text: &StringBuffer,
}
WriteMode::Plain => {
let stdout = stdout();
let stdout_lock = stdout.lock();
try!(write_system_newlines(stdout_lock, text, config));
let stdout = stdout.lock();
try!(write_system_newlines(stdout, text, config));
}
WriteMode::Display | WriteMode::Coverage => {
println!("{}:\n", filename);
let stdout = stdout();
let stdout_lock = stdout.lock();
try!(write_system_newlines(stdout_lock, text, config));
let stdout = stdout.lock();
try!(write_system_newlines(stdout, text, config));
}
WriteMode::Diff => {
println!("Diff of {}:\n", filename);
Expand Down

0 comments on commit 154e20a

Please sign in to comment.