@@ -55,6 +55,10 @@ enum Operation {
5555 ConfigOutputDefault {
5656 path : Option < String > ,
5757 } ,
58+ /// Output current config (as if formatting to a file) to stdout
59+ ConfigOutputCurrent {
60+ path : Option < String > ,
61+ } ,
5862 /// No file specified, read from stdin
5963 Stdin {
6064 input : String ,
@@ -103,8 +107,9 @@ fn make_opts() -> Options {
103107 "" ,
104108 "print-config" ,
105109 "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" ,
108113 ) ;
109114
110115 if is_nightly {
@@ -182,6 +187,21 @@ fn execute(opts: &Options) -> Result<i32, failure::Error> {
182187 }
183188 Ok ( 0 )
184189 }
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+ }
185205 Operation :: Stdin { input } => format_string ( input, options) ,
186206 Operation :: Format {
187207 files,
@@ -379,6 +399,8 @@ fn determine_operation(matches: &Matches) -> Result<Operation, ErrorKind> {
379399 let path = matches. free . get ( 0 ) . cloned ( ) ;
380400 if kind == "default" {
381401 return Ok ( Operation :: ConfigOutputDefault { path } ) ;
402+ } else if kind == "current" {
403+ return Ok ( Operation :: ConfigOutputCurrent { path } ) ;
382404 } else if kind == "minimal" {
383405 minimal_config_path = path;
384406 if minimal_config_path. is_none ( ) {
0 commit comments