Skip to content

Implemented 'unstable options' command line option #1998

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
Oct 29, 2017
Merged
Show file tree
Hide file tree
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
19 changes: 19 additions & 0 deletions src/bin/rustfmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,25 @@ struct CliOptions {
verbose: bool,
write_mode: Option<WriteMode>,
file_lines: FileLines, // Default is all lines in all files.
unstable_features: 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")
.map(|c| c == "nightly")
.unwrap_or(false);
if unstable_features && !rust_nightly {
return Err(FmtError::from(format!(
"Unstable features are only available on Nightly channel"
)));
} else {
options.unstable_features = unstable_features;
}

if let Some(ref write_mode) = matches.opt_str("write-mode") {
if let Ok(write_mode) = WriteMode::from_str(write_mode) {
Expand All @@ -89,6 +101,7 @@ impl CliOptions {
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);
if let Some(write_mode) = self.write_mode {
config.set().write_mode(write_mode);
}
Expand Down Expand Up @@ -120,6 +133,12 @@ fn make_opts() -> Options {
);
opts.optflag("", "skip-children", "don't reformat child modules");

opts.optflag(
"",
"unstable-features",
"Enables unstable features. Only available on nightly channel",
);

opts.optflag(
"",
"config-help",
Expand Down
Loading