diff --git a/src/bin/main.rs b/src/bin/main.rs index 7290c2f30d5..661502a2e0e 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -73,6 +73,14 @@ pub enum OperationError { /// An io error during reading or writing. #[fail(display = "io error: {}", _0)] IoError(IoError), + /// Attempt to use --check with stdin, which isn't currently + /// supported. + #[fail(display = "The `--check` option is not supported with standard input.")] + CheckWithStdin, + /// Attempt to use --emit=json with stdin, which isn't currently + /// supported. + #[fail(display = "Using `--emit` other than stdout is not supported with standard input.")] + EmitWithStdin, } impl From for OperationError { @@ -242,6 +250,14 @@ fn format_string(input: String, options: GetOptsOptions) -> Result, inline_config: HashMap, - emit_mode: EmitMode, + emit_mode: Option, backup: bool, check: bool, edition: Option, @@ -574,7 +590,7 @@ impl GetOptsOptions { return Err(format_err!("Invalid to use `--emit` and `--check`")); } - options.emit_mode = emit_mode_from_emit_str(emit_str)?; + options.emit_mode = Some(emit_mode_from_emit_str(emit_str)?); } if let Some(ref edition_str) = matches.opt_str("edition") { @@ -590,11 +606,13 @@ impl GetOptsOptions { } if !rust_nightly { - if !STABLE_EMIT_MODES.contains(&options.emit_mode) { - return Err(format_err!( - "Invalid value for `--emit` - using an unstable \ - value without `--unstable-features`", - )); + if let Some(ref emit_mode) = options.emit_mode { + if !STABLE_EMIT_MODES.contains(emit_mode) { + return Err(format_err!( + "Invalid value for `--emit` - using an unstable \ + value without `--unstable-features`", + )); + } } } @@ -643,8 +661,8 @@ impl CliOptions for GetOptsOptions { } if self.check { config.set().emit_mode(EmitMode::Diff); - } else { - config.set().emit_mode(self.emit_mode); + } else if let Some(emit_mode) = self.emit_mode { + config.set().emit_mode(emit_mode); } if self.backup { config.set().make_backup(true);