about summary refs log tree commit diff
path: root/src/bin
diff options
context:
space:
mode:
authorSeo Sanghyeon <sanxiyn@gmail.com>2015-11-15 15:41:41 +0900
committerSeo Sanghyeon <sanxiyn@gmail.com>2015-11-15 15:41:41 +0900
commitfaff4bc9e83e795c5d94ce7cfee9893459abd439 (patch)
tree2090c70a8d6e820eb857f2a19ad3ba285061fc6f /src/bin
parentcdf56f75a1fa3736c414ca6c96a58b21f4dc90fb (diff)
Add verbose mode
Diffstat (limited to 'src/bin')
-rw-r--r--src/bin/rustfmt.rs29
1 files changed, 18 insertions, 11 deletions
diff --git a/src/bin/rustfmt.rs b/src/bin/rustfmt.rs
index b90cdb3d3ca..789f8773345 100644
--- a/src/bin/rustfmt.rs
+++ b/src/bin/rustfmt.rs
@@ -25,7 +25,7 @@ use std::fs::{self, File};
 use std::io::{self, Read, Write};
 use std::path::{Path, PathBuf};
 
-use getopts::Options;
+use getopts::{Matches, Options};
 
 /// Rustfmt operations.
 enum Operation {
@@ -75,9 +75,14 @@ fn lookup_and_read_project_file(input_file: &Path) -> io::Result<(PathBuf, Strin
     Ok((path, toml))
 }
 
+fn update_config(config: &mut Config, matches: &Matches) {
+    config.verbose = matches.opt_present("verbose");
+}
+
 fn execute() -> i32 {
     let mut opts = Options::new();
     opts.optflag("h", "help", "show this message");
+    opts.optflag("v", "verbose", "show progress");
     opts.optopt("",
                 "write-mode",
                 "mode to write in (not usable when piping from stdin)",
@@ -87,7 +92,15 @@ fn execute() -> i32 {
                  "config-help",
                  "show details of rustfmt configuration options");
 
-    let operation = determine_operation(&opts, env::args().skip(1));
+    let matches = match opts.parse(env::args().skip(1)) {
+        Ok(m) => m,
+        Err(e) => {
+            print_usage(&opts, &e.to_string());
+            return 1;
+        }
+    };
+
+    let operation = determine_operation(&matches);
 
     match operation {
         Operation::InvalidInput(reason) => {
@@ -116,7 +129,7 @@ fn execute() -> i32 {
         }
         Operation::Format(files, write_mode) => {
             for file in files {
-                let config = match lookup_and_read_project_file(&file) {
+                let mut config = match lookup_and_read_project_file(&file) {
                     Ok((path, toml)) => {
                         println!("Using rustfmt config file {} for {}",
                                  path.display(),
@@ -126,6 +139,7 @@ fn execute() -> i32 {
                     Err(_) => Default::default(),
                 };
 
+                update_config(&mut config, &matches);
                 run(&file, write_mode, &config);
             }
             0
@@ -154,14 +168,7 @@ fn print_usage(opts: &Options, reason: &str) {
     println!("{}", opts.usage(&reason));
 }
 
-fn determine_operation<I>(opts: &Options, args: I) -> Operation
-    where I: Iterator<Item = String>
-{
-    let matches = match opts.parse(args) {
-        Ok(m) => m,
-        Err(e) => return Operation::InvalidInput(e.to_string()),
-    };
-
+fn determine_operation(matches: &Matches) -> Operation {
     if matches.opt_present("h") {
         return Operation::Help;
     }