@@ -110,20 +110,6 @@ fn make_opts() -> Options {
110
110
found reverts to the input file path",
111
111
"[Path for the configuration file]" ,
112
112
) ;
113
- opts. opt (
114
- "" ,
115
- "dump-default-config" ,
116
- "Dumps default configuration to PATH. PATH defaults to stdout, if omitted." ,
117
- "PATH" ,
118
- getopts:: HasArg :: Maybe ,
119
- getopts:: Occur :: Optional ,
120
- ) ;
121
- opts. optopt (
122
- "" ,
123
- "dump-minimal-config" ,
124
- "Dumps configuration options that were checked during formatting to a file." ,
125
- "PATH" ,
126
- ) ;
127
113
opts. optflag (
128
114
"" ,
129
115
"error-on-unformatted" ,
@@ -142,6 +128,13 @@ fn make_opts() -> Options {
142
128
"Show this message or help about a specific topic: config or file-lines" ,
143
129
"=TOPIC" ,
144
130
) ;
131
+ opts. optopt (
132
+ "" ,
133
+ "print-config" ,
134
+ "Dumps a default or minimal config to PATH. A minimal config is the \
135
+ subset of the current config file used for formatting the current program.",
136
+ "[minimal|default] PATH" ,
137
+ ) ;
145
138
opts. optflag ( "" , "skip-children" , "Don't reformat child modules" ) ;
146
139
opts. optflag (
147
140
"" ,
@@ -361,29 +354,24 @@ fn determine_operation(matches: &Matches) -> FmtResult<Operation> {
361
354
}
362
355
}
363
356
364
- if matches. opt_present ( "dump-default-config" ) {
365
- // NOTE for some reason when configured with HasArg::Maybe + Occur::Optional opt_default
366
- // doesn't recognize `--foo bar` as a long flag with an argument but as a long flag with no
367
- // argument *plus* a free argument. Thus we check for that case in this branch -- this is
368
- // required for backward compatibility.
369
- if let Some ( path) = matches. free . get ( 0 ) {
370
- return Ok ( Operation :: ConfigOutputDefault {
371
- path : Some ( path. clone ( ) ) ,
372
- } ) ;
373
- } else {
374
- return Ok ( Operation :: ConfigOutputDefault {
375
- path : matches. opt_str ( "dump-default-config" ) ,
376
- } ) ;
357
+ let mut minimal_config_path = None ;
358
+ if matches. opt_present ( "print-config" ) {
359
+ let kind = matches. opt_str ( "print-config" ) ;
360
+ let path = matches. free . get ( 0 ) ;
361
+ if kind == "default" {
362
+ return Ok ( Operation :: ConfigOutputDefault { path : path. clone ( ) } ) ;
363
+ } else if kind = "minimal" {
364
+ minimal_config_path = path;
365
+ if minimal_config_path. is_none ( ) {
366
+ println ! ( "WARNING: PATH required for `--print-config minimal`" ) ;
367
+ }
377
368
}
378
369
}
379
370
380
371
if matches. opt_present ( "version" ) {
381
372
return Ok ( Operation :: Version ) ;
382
373
}
383
374
384
- // If no path is given, we won't output a minimal config.
385
- let minimal_config_path = matches. opt_str ( "dump-minimal-config" ) ;
386
-
387
375
// if no file argument is supplied, read from stdin
388
376
if matches. free . is_empty ( ) {
389
377
let mut buffer = String :: new ( ) ;
0 commit comments