about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorNick Cameron <ncameron@mozilla.com>2018-05-13 14:13:24 +1200
committerNick Cameron <ncameron@mozilla.com>2018-05-13 14:13:24 +1200
commit5d9f5aa05a668e7dfef87b46d89dad2884df9d41 (patch)
treebd5fe0300090045a7588ec18295ebff2038e64e8 /src
parent8396da188251ae8d6d2970a497ecdf07bf4ef04f (diff)
Replace `--write-mode` with `--emit`
cc #1976
Diffstat (limited to 'src')
-rw-r--r--src/bin/main.rs11
-rw-r--r--src/config/options.rs20
-rw-r--r--src/config/summary.rs2
-rw-r--r--src/lib.rs3
-rw-r--r--src/test/mod.rs13
5 files changed, 22 insertions, 27 deletions
diff --git a/src/bin/main.rs b/src/bin/main.rs
index c903ba18561..b8f5225633f 100644
--- a/src/bin/main.rs
+++ b/src/bin/main.rs
@@ -111,6 +111,7 @@ fn make_opts() -> Options {
          found reverts to the input file path",
         "[Path for the configuration file]",
     );
+    opts.optopt("", "emit", "What data to emit and how", WRITE_MODE_LIST);
     opts.optflag(
         "",
         "error-on-unformatted",
@@ -120,13 +121,13 @@ fn make_opts() -> Options {
     opts.optopt(
         "",
         "file-lines",
-        "Format specified line ranges. See README for more detail on the JSON format.",
+        "Format specified line ranges. Run with `--help file-lines` for more detail.",
         "JSON",
     );
     opts.optflagopt(
         "h",
         "help",
-        "Show this message or help about a specific topic: config or file-lines",
+        "Show this message or help about a specific topic: `config` or `file-lines`",
         "=TOPIC",
     );
     opts.optopt(
@@ -145,12 +146,6 @@ fn make_opts() -> Options {
     opts.optflag("v", "verbose", "Print verbose output");
     opts.optflag("q", "quiet", "Print less output");
     opts.optflag("V", "version", "Show version information");
-    opts.optopt(
-        "",
-        "write-mode",
-        "How to write output (not usable when piping from stdin)",
-        WRITE_MODE_LIST,
-    );
 
     opts
 }
diff --git a/src/config/options.rs b/src/config/options.rs
index b3c0acb854e..e4ba87a88f8 100644
--- a/src/config/options.rs
+++ b/src/config/options.rs
@@ -363,11 +363,11 @@ impl CliOptions {
         options.config_path = matches.opt_str("config-path").map(PathBuf::from);
 
         options.check = matches.opt_present("check");
-        if let Some(ref write_mode) = matches.opt_str("write-mode") {
+        if let Some(ref emit_str) = matches.opt_str("emit") {
             if options.check {
-                return Err(format_err!("Invalid to set write-mode and `--check`"));
+                return Err(format_err!("Invalid to use `--emit` and `--check`"));
             }
-            if let Ok(write_mode) = WriteMode::from_str(write_mode) {
+            if let Ok(write_mode) = write_mode_from_emit_str(emit_str) {
                 if write_mode == WriteMode::Overwrite && matches.opt_present("backup") {
                     options.write_mode = Some(WriteMode::Replace);
                 } else {
@@ -375,8 +375,8 @@ impl CliOptions {
                 }
             } else {
                 return Err(format_err!(
-                    "Invalid write-mode: {}, expected one of {}",
-                    write_mode,
+                    "Invalid value for `--emit`: {}, expected one of {}",
+                    emit_str,
                     WRITE_MODE_LIST
                 ));
             }
@@ -441,3 +441,13 @@ impl CliOptions {
         }
     }
 }
+
+fn write_mode_from_emit_str(emit_str: &str) -> FmtResult<WriteMode> {
+    match emit_str {
+        "files" => Ok(WriteMode::Overwrite),
+        "stdout" => Ok(WriteMode::Display),
+        "coverage" => Ok(WriteMode::Coverage),
+        "checkstyle" => Ok(WriteMode::Checkstyle),
+        _ => Err(format_err!("Invalid value for `--emit`")),
+    }
+}
diff --git a/src/config/summary.rs b/src/config/summary.rs
index 9f339b61be7..e436856d286 100644
--- a/src/config/summary.rs
+++ b/src/config/summary.rs
@@ -23,7 +23,7 @@ pub struct Summary {
     // Code is valid, but it is impossible to format it properly.
     has_formatting_errors: bool,
 
-    // Formatted code differs from existing code (write-mode diff only).
+    // Formatted code differs from existing code (--check only).
     pub has_diff: bool,
 
     // Keeps track of time spent in parsing and formatting steps.
diff --git a/src/lib.rs b/src/lib.rs
index e30f4d586bd..5fb3e4b03e3 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -68,7 +68,8 @@ pub use config::{file_lines, load_config, Config, Verbosity, WriteMode};
 
 pub type FmtResult<T> = std::result::Result<T, failure::Error>;
 
-pub const WRITE_MODE_LIST: &str = "[overwrite|display|plain|diff|coverage|checkstyle]";
+// FIXME: this is badly named since the user-facing name is `emit` not `write-mode`.
+pub const WRITE_MODE_LIST: &str = "[files|stdout|coverage|checkstyle]";
 
 #[macro_use]
 mod utils;
diff --git a/src/test/mod.rs b/src/test/mod.rs
index 631c8076ca7..4de69296e9f 100644
--- a/src/test/mod.rs
+++ b/src/test/mod.rs
@@ -912,18 +912,7 @@ fn verify_check_works() {
     let temp_file = make_temp_file("temp_check.rs");
     assert_cli::Assert::command(&[
         rustfmt().to_str().unwrap(),
-        "--write-mode=check",
-        temp_file.path.to_str().unwrap(),
-    ]).succeeds()
-        .unwrap();
-}
-
-#[test]
-fn verify_diff_works() {
-    let temp_file = make_temp_file("temp_diff.rs");
-    assert_cli::Assert::command(&[
-        rustfmt().to_str().unwrap(),
-        "--write-mode=diff",
+        "--check",
         temp_file.path.to_str().unwrap(),
     ]).succeeds()
         .unwrap();