@@ -55,6 +55,10 @@ enum Operation {
55
55
ConfigOutputDefault {
56
56
path : Option < String > ,
57
57
} ,
58
+ /// Output current config (as if formatting to a file) to stdout
59
+ ConfigOutputCurrent {
60
+ path : Option < String > ,
61
+ } ,
58
62
/// No file specified, read from stdin
59
63
Stdin {
60
64
input : String ,
@@ -103,8 +107,9 @@ fn make_opts() -> Options {
103
107
"" ,
104
108
"print-config" ,
105
109
"Dumps a default or minimal config to PATH. A minimal config is the \
106
- subset of the current config file used for formatting the current program.",
107
- "[minimal|default] PATH" ,
110
+ subset of the current config file used for formatting the current program. \
111
+ `current` writes to stdout current config as if formatting the file at PATH.",
112
+ "[default|minimal|current] PATH" ,
108
113
) ;
109
114
110
115
if is_nightly {
@@ -182,6 +187,21 @@ fn execute(opts: &Options) -> Result<i32, failure::Error> {
182
187
}
183
188
Ok ( 0 )
184
189
}
190
+ Operation :: ConfigOutputCurrent { path } => {
191
+ let path = match path {
192
+ Some ( path) => path,
193
+ None => return Err ( format_err ! ( "PATH required for `--print-config current`" ) ) ,
194
+ } ;
195
+
196
+ let file = PathBuf :: from ( path) ;
197
+ let file = file. canonicalize ( ) . unwrap_or ( file) ;
198
+
199
+ let ( config, _) = load_config ( Some ( file. parent ( ) . unwrap ( ) ) , Some ( options. clone ( ) ) ) ?;
200
+ let toml = config. all_options ( ) . to_toml ( ) . map_err ( err_msg) ?;
201
+ io:: stdout ( ) . write_all ( toml. as_bytes ( ) ) ?;
202
+
203
+ Ok ( 0 )
204
+ }
185
205
Operation :: Stdin { input } => format_string ( input, options) ,
186
206
Operation :: Format {
187
207
files,
@@ -379,6 +399,8 @@ fn determine_operation(matches: &Matches) -> Result<Operation, ErrorKind> {
379
399
let path = matches. free . get ( 0 ) . cloned ( ) ;
380
400
if kind == "default" {
381
401
return Ok ( Operation :: ConfigOutputDefault { path } ) ;
402
+ } else if kind == "current" {
403
+ return Ok ( Operation :: ConfigOutputCurrent { path } ) ;
382
404
} else if kind == "minimal" {
383
405
minimal_config_path = path;
384
406
if minimal_config_path. is_none ( ) {
0 commit comments