@@ -35,11 +35,9 @@ const WRITE_MODE_LIST: &str = "[replace|overwrite|display|plain|diff|coverage|ch
35
35
fn main ( ) {
36
36
env_logger:: init ( ) ;
37
37
let opts = make_opts ( ) ;
38
- // Only handles arguments passed in through the CLI.
39
- let write_mode = determine_write_mode ( & opts) ;
40
38
41
39
let exit_code = match execute ( & opts) {
42
- Ok ( summary) => {
40
+ Ok ( ( write_mode , summary) ) => {
43
41
if summary. has_operational_errors ( )
44
42
|| summary. has_diff && write_mode == WriteMode :: Check
45
43
|| summary. has_parsing_errors ( ) || summary. has_formatting_errors ( )
@@ -248,22 +246,22 @@ fn make_opts() -> Options {
248
246
opts
249
247
}
250
248
251
- fn execute ( opts : & Options ) -> FmtResult < Summary > {
249
+ fn execute ( opts : & Options ) -> FmtResult < ( WriteMode , Summary ) > {
252
250
let matches = opts. parse ( env:: args ( ) . skip ( 1 ) ) ?;
253
251
254
252
match determine_operation ( & matches) ? {
255
253
Operation :: Help => {
256
254
print_usage_to_stdout ( opts, "" ) ;
257
255
Summary :: print_exit_codes ( ) ;
258
- Ok ( Summary :: default ( ) )
256
+ Ok ( ( WriteMode :: None , Summary :: default ( ) ) )
259
257
}
260
258
Operation :: Version => {
261
259
print_version ( ) ;
262
- Ok ( Summary :: default ( ) )
260
+ Ok ( ( WriteMode :: None , Summary :: default ( ) ) )
263
261
}
264
262
Operation :: ConfigHelp => {
265
263
Config :: print_docs ( & mut stdout ( ) , matches. opt_present ( "unstable-features" ) ) ;
266
- Ok ( Summary :: default ( ) )
264
+ Ok ( ( WriteMode :: None , Summary :: default ( ) ) )
267
265
}
268
266
Operation :: ConfigOutputDefault { path } => {
269
267
let toml = Config :: default ( ) . all_options ( ) . to_toml ( ) ?;
@@ -273,7 +271,7 @@ fn execute(opts: &Options) -> FmtResult<Summary> {
273
271
} else {
274
272
io:: stdout ( ) . write_all ( toml. as_bytes ( ) ) ?;
275
273
}
276
- Ok ( Summary :: default ( ) )
274
+ Ok ( ( WriteMode :: None , Summary :: default ( ) ) )
277
275
}
278
276
Operation :: Stdin { input, config_path } => {
279
277
// try to read config from local directory
@@ -302,7 +300,7 @@ fn execute(opts: &Options) -> FmtResult<Summary> {
302
300
checkstyle:: output_footer ( & mut out, config. write_mode ( ) ) ?;
303
301
}
304
302
305
- Ok ( error_summary)
303
+ Ok ( ( WriteMode :: Plain , error_summary) )
306
304
}
307
305
Operation :: Format {
308
306
files,
@@ -320,7 +318,7 @@ fn format(
320
318
config_path : Option < PathBuf > ,
321
319
minimal_config_path : Option < String > ,
322
320
options : CliOptions ,
323
- ) -> FmtResult < Summary > {
321
+ ) -> FmtResult < ( WriteMode , Summary ) > {
324
322
for f in options. file_lines . files ( ) {
325
323
match * f {
326
324
FileName :: Real ( ref f) if files. contains ( f) => { }
@@ -343,8 +341,9 @@ fn format(
343
341
}
344
342
}
345
343
344
+ let write_mode = config. write_mode ( ) ;
346
345
let mut out = & mut stdout ( ) ;
347
- checkstyle:: output_header ( & mut out, config . write_mode ( ) ) ?;
346
+ checkstyle:: output_header ( & mut out, write_mode) ?;
348
347
let mut error_summary = Summary :: default ( ) ;
349
348
350
349
for file in files {
@@ -379,7 +378,7 @@ fn format(
379
378
error_summary. add ( run ( Input :: File ( file) , & config) ) ;
380
379
}
381
380
}
382
- checkstyle:: output_footer ( & mut out, config . write_mode ( ) ) ?;
381
+ checkstyle:: output_footer ( & mut out, write_mode) ?;
383
382
384
383
// If we were given a path via dump-minimal-config, output any options
385
384
// that were used during formatting as TOML.
@@ -389,16 +388,7 @@ fn format(
389
388
file. write_all ( toml. as_bytes ( ) ) ?;
390
389
}
391
390
392
- Ok ( error_summary)
393
- }
394
-
395
- fn determine_write_mode ( opts : & Options ) -> WriteMode {
396
- let matches = opts. parse ( env:: args ( ) . skip ( 1 ) ) . unwrap ( ) ;
397
- let options = CliOptions :: from_matches ( & matches) . unwrap ( ) ;
398
- match options. write_mode {
399
- Some ( m) => m,
400
- None => WriteMode :: default ( ) ,
401
- }
391
+ Ok ( ( write_mode, error_summary) )
402
392
}
403
393
404
394
fn print_usage_to_stdout ( opts : & Options , reason : & str ) {
0 commit comments