Skip to content

Commit c673723

Browse files
committed
config: Use PartialConfig for verbose and skip_children
1 parent d0e4db9 commit c673723

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/bin/rustfmt.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,16 @@ fn resolve_config(dir: &Path) -> io::Result<(Config, Option<PathBuf>)> {
9696
Ok((Config::from(parsed_config), Some(path)))
9797
}
9898

99-
fn update_config(config: &mut Config, matches: &Matches) {
100-
config.verbose = matches.opt_present("verbose");
101-
config.skip_children = matches.opt_present("skip-children");
99+
fn partial_config_from_options(matches: &Matches) -> PartialConfig {
100+
let mut config = PartialConfig::new();
101+
if matches.opt_present("skip_children") {
102+
config.skip_children = Some(true);
103+
}
104+
if matches.opt_present("verbose") {
105+
config.verbose = Some(true);
106+
}
107+
108+
config
102109
}
103110

104111
fn execute() -> i32 {
@@ -156,13 +163,13 @@ fn execute() -> i32 {
156163
let (mut config, path) = resolve_config(file.parent().unwrap())
157164
.expect(&format!("Error resolving config for {}",
158165
file.display()));
166+
config = config.merge(&partial_config_from_options(&matches));
159167
if let Some(path) = path {
160168
println!("Using rustfmt config file {} for {}",
161169
path.display(),
162170
file.display());
163171
}
164172

165-
update_config(&mut config, &matches);
166173
run(&file, write_mode, &config);
167174
}
168175
0

0 commit comments

Comments
 (0)