Skip to content

Commit eca7796

Browse files
committed
Replace --dump-minimal-config and --dump-default-config with --print-config
cc #1976
1 parent 4d9de48 commit eca7796

File tree

1 file changed

+18
-30
lines changed

1 file changed

+18
-30
lines changed

src/bin/main.rs

+18-30
Original file line numberDiff line numberDiff line change
@@ -110,20 +110,6 @@ fn make_opts() -> Options {
110110
found reverts to the input file path",
111111
"[Path for the configuration file]",
112112
);
113-
opts.opt(
114-
"",
115-
"dump-default-config",
116-
"Dumps default configuration to PATH. PATH defaults to stdout, if omitted.",
117-
"PATH",
118-
getopts::HasArg::Maybe,
119-
getopts::Occur::Optional,
120-
);
121-
opts.optopt(
122-
"",
123-
"dump-minimal-config",
124-
"Dumps configuration options that were checked during formatting to a file.",
125-
"PATH",
126-
);
127113
opts.optflag(
128114
"",
129115
"error-on-unformatted",
@@ -142,6 +128,13 @@ fn make_opts() -> Options {
142128
"Show this message or help about a specific topic: config or file-lines",
143129
"=TOPIC",
144130
);
131+
opts.optopt(
132+
"",
133+
"print-config",
134+
"Dumps a default or minimal config to PATH. A minimal config is the \
135+
subset of the current config file used for formatting the current program.",
136+
"[minimal|default] PATH",
137+
);
145138
opts.optflag("", "skip-children", "Don't reformat child modules");
146139
opts.optflag(
147140
"",
@@ -361,29 +354,24 @@ fn determine_operation(matches: &Matches) -> FmtResult<Operation> {
361354
}
362355
}
363356

364-
if matches.opt_present("dump-default-config") {
365-
// NOTE for some reason when configured with HasArg::Maybe + Occur::Optional opt_default
366-
// doesn't recognize `--foo bar` as a long flag with an argument but as a long flag with no
367-
// argument *plus* a free argument. Thus we check for that case in this branch -- this is
368-
// required for backward compatibility.
369-
if let Some(path) = matches.free.get(0) {
370-
return Ok(Operation::ConfigOutputDefault {
371-
path: Some(path.clone()),
372-
});
373-
} else {
374-
return Ok(Operation::ConfigOutputDefault {
375-
path: matches.opt_str("dump-default-config"),
376-
});
357+
let mut minimal_config_path = None;
358+
if matches.opt_present("print-config") {
359+
let kind = matches.opt_str("print-config");
360+
let path = matches.free.get(0);
361+
if kind == "default" {
362+
return Ok(Operation::ConfigOutputDefault { path: path.clone() });
363+
} else if kind = "minimal" {
364+
minimal_config_path = path;
365+
if minimal_config_path.is_none() {
366+
println!("WARNING: PATH required for `--print-config minimal`");
367+
}
377368
}
378369
}
379370

380371
if matches.opt_present("version") {
381372
return Ok(Operation::Version);
382373
}
383374

384-
// If no path is given, we won't output a minimal config.
385-
let minimal_config_path = matches.opt_str("dump-minimal-config");
386-
387375
// if no file argument is supplied, read from stdin
388376
if matches.free.is_empty() {
389377
let mut buffer = String::new();

0 commit comments

Comments
 (0)