Skip to content

Commit

Permalink
Replace --dump-minimal-config and --dump-default-config with `--p…
Browse files Browse the repository at this point in the history
…rint-config`

cc #1976
  • Loading branch information
nrc committed May 11, 2018
1 parent 4d9de48 commit eca7796
Showing 1 changed file with 18 additions and 30 deletions.
48 changes: 18 additions & 30 deletions src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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(
"",
Expand Down Expand Up @@ -361,29 +354,24 @@ fn determine_operation(matches: &Matches) -> FmtResult<Operation> {
}
}

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`");
}
}
}

if matches.opt_present("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 matches.free.is_empty() {
let mut buffer = String::new();
Expand Down

0 comments on commit eca7796

Please sign in to comment.