Replace --dump-minimal-config and --dump-default-config with --print-config

cc #1976
This commit is contained in:
Nick Cameron 2018-05-11 20:43:08 +12:00
parent 4d9de48e06
commit eca7796fb1

View file

@ -110,20 +110,6 @@ fn make_opts() -> Options {
found reverts to the input file path", found reverts to the input file path",
"[Path for the configuration file]", "[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( opts.optflag(
"", "",
"error-on-unformatted", "error-on-unformatted",
@ -142,6 +128,13 @@ fn make_opts() -> Options {
"Show this message or help about a specific topic: config or file-lines", "Show this message or help about a specific topic: config or file-lines",
"=TOPIC", "=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("", "skip-children", "Don't reformat child modules");
opts.optflag( opts.optflag(
"", "",
@ -361,19 +354,17 @@ fn determine_operation(matches: &Matches) -> FmtResult<Operation> {
} }
} }
if matches.opt_present("dump-default-config") { let mut minimal_config_path = None;
// NOTE for some reason when configured with HasArg::Maybe + Occur::Optional opt_default if matches.opt_present("print-config") {
// doesn't recognize `--foo bar` as a long flag with an argument but as a long flag with no let kind = matches.opt_str("print-config");
// argument *plus* a free argument. Thus we check for that case in this branch -- this is let path = matches.free.get(0);
// required for backward compatibility. if kind == "default" {
if let Some(path) = matches.free.get(0) { return Ok(Operation::ConfigOutputDefault { path: path.clone() });
return Ok(Operation::ConfigOutputDefault { } else if kind = "minimal" {
path: Some(path.clone()), minimal_config_path = path;
}); if minimal_config_path.is_none() {
} else { println!("WARNING: PATH required for `--print-config minimal`");
return Ok(Operation::ConfigOutputDefault { }
path: matches.opt_str("dump-default-config"),
});
} }
} }
@ -381,9 +372,6 @@ fn determine_operation(matches: &Matches) -> FmtResult<Operation> {
return Ok(Operation::Version); 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 no file argument is supplied, read from stdin
if matches.free.is_empty() { if matches.free.is_empty() {
let mut buffer = String::new(); let mut buffer = String::new();