From eca7796fb1cd8866189e273f7e5d1df5585b269e Mon Sep 17 00:00:00 2001 From: Nick Cameron Date: Fri, 11 May 2018 20:43:08 +1200 Subject: [PATCH] Replace `--dump-minimal-config` and `--dump-default-config` with `--print-config` cc #1976 --- src/bin/main.rs | 48 ++++++++++++++++++------------------------------ 1 file changed, 18 insertions(+), 30 deletions(-) diff --git a/src/bin/main.rs b/src/bin/main.rs index f01c260adffe..ee17c024e69e 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -110,20 +110,6 @@ fn make_opts() -> Options { found reverts to the input file path", "[Path for the configuration file]", ); - opts.opt( - "", - "dump-default-config", - "Dumps default configuration to PATH. PATH defaults to stdout, if omitted.", - "PATH", - getopts::HasArg::Maybe, - getopts::Occur::Optional, - ); - opts.optopt( - "", - "dump-minimal-config", - "Dumps configuration options that were checked during formatting to a file.", - "PATH", - ); opts.optflag( "", "error-on-unformatted", @@ -142,6 +128,13 @@ fn make_opts() -> Options { "Show this message or help about a specific topic: config or file-lines", "=TOPIC", ); + opts.optopt( + "", + "print-config", + "Dumps a default or minimal config to PATH. A minimal config is the \ + subset of the current config file used for formatting the current program.", + "[minimal|default] PATH", + ); opts.optflag("", "skip-children", "Don't reformat child modules"); opts.optflag( "", @@ -361,19 +354,17 @@ fn determine_operation(matches: &Matches) -> FmtResult { } } - if matches.opt_present("dump-default-config") { - // NOTE for some reason when configured with HasArg::Maybe + Occur::Optional opt_default - // doesn't recognize `--foo bar` as a long flag with an argument but as a long flag with no - // argument *plus* a free argument. Thus we check for that case in this branch -- this is - // required for backward compatibility. - if let Some(path) = matches.free.get(0) { - return Ok(Operation::ConfigOutputDefault { - path: Some(path.clone()), - }); - } else { - return Ok(Operation::ConfigOutputDefault { - path: matches.opt_str("dump-default-config"), - }); + let mut minimal_config_path = None; + if matches.opt_present("print-config") { + let kind = matches.opt_str("print-config"); + let path = matches.free.get(0); + if kind == "default" { + return Ok(Operation::ConfigOutputDefault { path: path.clone() }); + } else if kind = "minimal" { + minimal_config_path = path; + if minimal_config_path.is_none() { + println!("WARNING: PATH required for `--print-config minimal`"); + } } } @@ -381,9 +372,6 @@ fn determine_operation(matches: &Matches) -> FmtResult { return Ok(Operation::Version); } - // If no path is given, we won't output a minimal config. - let minimal_config_path = matches.opt_str("dump-minimal-config"); - // if no file argument is supplied, read from stdin if matches.free.is_empty() { let mut buffer = String::new();