From 3fe2233fd3281f80bf3109b4aebb2323fdf58649 Mon Sep 17 00:00:00 2001 From: Ivan Sorokin Date: Sat, 31 Mar 2018 14:27:39 +0200 Subject: [PATCH] Fix error_on_unformatted and skip_children override Currently, error_on_unformatted and skip_children options specified in the config file are discarded. This happens because CLI options have a higher priority, but we coerce an absence of a `bool` option to `false`. In this scenario, an absence of a `bool` option is indistinguishable from explicetely set as `false`. We should coerce it to `None` instead, so it does not override the one in the config file. --- src/bin/main.rs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/bin/main.rs b/src/bin/main.rs index 109bc90aadd..3ad2d3088f0 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -57,19 +57,18 @@ enum Operation { /// Parsed command line options. #[derive(Clone, Debug, Default)] struct CliOptions { - skip_children: bool, + skip_children: Option, verbose: bool, write_mode: Option, color: Option, file_lines: FileLines, // Default is all lines in all files. unstable_features: bool, - error_on_unformatted: bool, + error_on_unformatted: Option, } impl CliOptions { fn from_matches(matches: &Matches) -> FmtResult { let mut options = CliOptions::default(); - options.skip_children = matches.opt_present("skip-children"); options.verbose = matches.opt_present("verbose"); let unstable_features = matches.opt_present("unstable-features"); let rust_nightly = option_env!("CFG_RELEASE_CHANNEL") @@ -105,19 +104,26 @@ impl CliOptions { options.file_lines = file_lines.parse()?; } + if matches.opt_present("skip-children") { + options.skip_children = Some(true); + } if matches.opt_present("error-on-unformatted") { - options.error_on_unformatted = true; + options.error_on_unformatted = Some(true); } Ok(options) } fn apply_to(self, config: &mut Config) { - config.set().skip_children(self.skip_children); config.set().verbose(self.verbose); config.set().file_lines(self.file_lines); config.set().unstable_features(self.unstable_features); - config.set().error_on_unformatted(self.error_on_unformatted); + if let Some(skip_children) = self.skip_children { + config.set().skip_children(skip_children); + } + if let Some(error_on_unformatted) = self.error_on_unformatted { + config.set().error_on_unformatted(error_on_unformatted); + } if let Some(write_mode) = self.write_mode { config.set().write_mode(write_mode); }