@@ -73,6 +73,14 @@ pub enum OperationError {
73
73
/// An io error during reading or writing.
74
74
#[ fail( display = "io error: {}" , _0) ]
75
75
IoError ( IoError ) ,
76
+ /// Attempt to use --check with stdin, which isn't currently
77
+ /// supported.
78
+ #[ fail( display = "The `--check` option is not supported with standard input." ) ]
79
+ CheckWithStdin ,
80
+ /// Attempt to use --emit=json with stdin, which isn't currently
81
+ /// supported.
82
+ #[ fail( display = "Using `--emit` other than stdout is not supported with standard input." ) ]
83
+ EmitWithStdin ,
76
84
}
77
85
78
86
impl From < IoError > for OperationError {
@@ -242,6 +250,14 @@ fn format_string(input: String, options: GetOptsOptions) -> Result<i32, FailureE
242
250
// try to read config from local directory
243
251
let ( mut config, _) = load_config ( Some ( Path :: new ( "." ) ) , Some ( options. clone ( ) ) ) ?;
244
252
253
+ if options. check {
254
+ return Err ( OperationError :: CheckWithStdin . into ( ) ) ;
255
+ }
256
+ if let Some ( emit_mode) = options. emit_mode {
257
+ if emit_mode != EmitMode :: Stdout {
258
+ return Err ( OperationError :: EmitWithStdin . into ( ) ) ;
259
+ }
260
+ }
245
261
// emit mode is always Stdout for Stdin.
246
262
config. set ( ) . emit_mode ( EmitMode :: Stdout ) ;
247
263
config. set ( ) . verbose ( Verbosity :: Quiet ) ;
@@ -486,7 +502,7 @@ struct GetOptsOptions {
486
502
verbose : bool ,
487
503
config_path : Option < PathBuf > ,
488
504
inline_config : HashMap < String , String > ,
489
- emit_mode : EmitMode ,
505
+ emit_mode : Option < EmitMode > ,
490
506
backup : bool ,
491
507
check : bool ,
492
508
edition : Option < Edition > ,
@@ -574,7 +590,7 @@ impl GetOptsOptions {
574
590
return Err ( format_err ! ( "Invalid to use `--emit` and `--check`" ) ) ;
575
591
}
576
592
577
- options. emit_mode = emit_mode_from_emit_str ( emit_str) ?;
593
+ options. emit_mode = Some ( emit_mode_from_emit_str ( emit_str) ?) ;
578
594
}
579
595
580
596
if let Some ( ref edition_str) = matches. opt_str ( "edition" ) {
@@ -590,11 +606,13 @@ impl GetOptsOptions {
590
606
}
591
607
592
608
if !rust_nightly {
593
- if !STABLE_EMIT_MODES . contains ( & options. emit_mode ) {
594
- return Err ( format_err ! (
595
- "Invalid value for `--emit` - using an unstable \
596
- value without `--unstable-features`",
597
- ) ) ;
609
+ if let Some ( ref emit_mode) = options. emit_mode {
610
+ if !STABLE_EMIT_MODES . contains ( emit_mode) {
611
+ return Err ( format_err ! (
612
+ "Invalid value for `--emit` - using an unstable \
613
+ value without `--unstable-features`",
614
+ ) ) ;
615
+ }
598
616
}
599
617
}
600
618
@@ -643,8 +661,8 @@ impl CliOptions for GetOptsOptions {
643
661
}
644
662
if self . check {
645
663
config. set ( ) . emit_mode ( EmitMode :: Diff ) ;
646
- } else {
647
- config. set ( ) . emit_mode ( self . emit_mode ) ;
664
+ } else if let Some ( emit_mode ) = self . emit_mode {
665
+ config. set ( ) . emit_mode ( emit_mode) ;
648
666
}
649
667
if self . backup {
650
668
config. set ( ) . make_backup ( true ) ;
0 commit comments