Skip to content

Fix error_on_unformatted and skip_children override #2600

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 6, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,18 @@ enum Operation {
/// Parsed command line options.
#[derive(Clone, Debug, Default)]
struct CliOptions {
skip_children: bool,
skip_children: Option<bool>,
verbose: bool,
write_mode: Option<WriteMode>,
color: Option<Color>,
file_lines: FileLines, // Default is all lines in all files.
unstable_features: bool,
error_on_unformatted: bool,
error_on_unformatted: Option<bool>,
}

impl CliOptions {
fn from_matches(matches: &Matches) -> FmtResult<CliOptions> {
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")
Expand Down Expand Up @@ -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);
}
Expand Down