From 154e20a04f7b3261c2d94e18f9abd39a056f6bef Mon Sep 17 00:00:00 2001 From: Johann Date: Tue, 3 Nov 2015 09:16:33 +0100 Subject: [PATCH] Address review concerns --- src/bin/rustfmt.rs | 21 ++++----------------- src/filemap.rs | 8 ++++---- 2 files changed, 8 insertions(+), 21 deletions(-) diff --git a/src/bin/rustfmt.rs b/src/bin/rustfmt.rs index f1dda3b1a79..b8eacc2bcd0 100644 --- a/src/bin/rustfmt.rs +++ b/src/bin/rustfmt.rs @@ -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)); @@ -153,21 +153,7 @@ fn determine_operation(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) { @@ -175,6 +161,7 @@ fn determine_operation(opts: &Options, args: I) -> Operation Err(e) => return Operation::InvalidInput(e.to_string()), } + // WriteMode is always plain for Stdin return Operation::Stdin(buffer, WriteMode::Plain); } diff --git a/src/filemap.rs b/src/filemap.rs index a11b89bc54b..3f1a867f385 100644 --- a/src/filemap.rs +++ b/src/filemap.rs @@ -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);