Skip to content

Commit f470541

Browse files
author
Peter Huene
committed
Suppress unstable config options by default.
This commit suppresses the output of unstable config options by default. Users can specify the `--unstable-features` option to show the config options that are unstable. Fixes #2611.
1 parent f146711 commit f470541

File tree

3 files changed

+46
-20
lines changed

3 files changed

+46
-20
lines changed

src/bin/main.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ extern crate getopts;
1515
extern crate rustfmt_nightly as rustfmt;
1616

1717
use std::fs::File;
18-
use std::io::{self, Read, Write};
18+
use std::io::{self, stdout, Read, Write};
1919
use std::path::{Path, PathBuf};
2020
use std::str::FromStr;
2121
use std::{env, error};
@@ -226,7 +226,7 @@ fn execute(opts: &Options) -> FmtResult<Summary> {
226226
Ok(Summary::default())
227227
}
228228
Operation::ConfigHelp => {
229-
Config::print_docs();
229+
Config::print_docs(&mut stdout(), matches.opt_present("unstable-features"));
230230
Ok(Summary::default())
231231
}
232232
Operation::ConfigOutputDefault { path } => {

src/config/config_type.rs

+22-18
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ macro_rules! is_nightly_channel {
8181
macro_rules! create_config {
8282
($($i:ident: $ty:ty, $def:expr, $stb:expr, $( $dstring:expr ),+ );+ $(;)*) => (
8383
use std::collections::HashSet;
84+
use std::io::Write;
8485

8586
#[derive(Clone)]
8687
pub struct Config {
@@ -359,33 +360,36 @@ macro_rules! create_config {
359360
HIDE_OPTIONS.contains(&name)
360361
}
361362

362-
pub fn print_docs() {
363+
pub fn print_docs(out: &mut Write, include_unstable: bool) {
363364
use std::cmp;
364365
let max = 0;
365366
$( let max = cmp::max(max, stringify!($i).len()+1); )+
366367
let mut space_str = String::with_capacity(max);
367368
for _ in 0..max {
368369
space_str.push(' ');
369370
}
370-
println!("Configuration Options:");
371+
writeln!(out, "Configuration Options:").unwrap();
371372
$(
372-
let name_raw = stringify!($i);
373-
374-
if !Config::is_hidden_option(name_raw) {
375-
let mut name_out = String::with_capacity(max);
376-
for _ in name_raw.len()..max-1 {
377-
name_out.push(' ')
373+
if $stb || include_unstable {
374+
let name_raw = stringify!($i);
375+
376+
if !Config::is_hidden_option(name_raw) {
377+
let mut name_out = String::with_capacity(max);
378+
for _ in name_raw.len()..max-1 {
379+
name_out.push(' ')
380+
}
381+
name_out.push_str(name_raw);
382+
name_out.push(' ');
383+
writeln!(out,
384+
"{}{} Default: {:?}",
385+
name_out,
386+
<$ty>::doc_hint(),
387+
$def).unwrap();
388+
$(
389+
writeln!(out, "{}{}", space_str, $dstring).unwrap();
390+
)+
391+
writeln!(out).unwrap();
378392
}
379-
name_out.push_str(name_raw);
380-
name_out.push(' ');
381-
println!("{}{} Default: {:?}",
382-
name_out,
383-
<$ty>::doc_hint(),
384-
$def);
385-
$(
386-
println!("{}{}", space_str, $dstring);
387-
)+
388-
println!();
389393
}
390394
)+
391395
}

src/config/mod.rs

+22
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ pub fn get_toml_path(dir: &Path) -> Result<Option<PathBuf>, Error> {
181181
#[cfg(test)]
182182
mod test {
183183
use super::Config;
184+
use std::str;
184185

185186
#[test]
186187
fn test_config_set() {
@@ -218,6 +219,27 @@ mod test {
218219
assert_eq!(config.was_set().verbose(), false);
219220
}
220221

222+
#[test]
223+
fn test_print_docs_without_unstable() {
224+
let mut output = Vec::new();
225+
Config::print_docs(&mut output, false);
226+
227+
let s = str::from_utf8(&output).unwrap();
228+
229+
assert_eq!(s.contains("newline_style"), true);
230+
assert_eq!(s.contains("use_small_heuristics"), false);
231+
}
232+
233+
#[test]
234+
fn test_print_docs_with_unstable() {
235+
let mut output = Vec::new();
236+
Config::print_docs(&mut output, true);
237+
238+
let s = str::from_utf8(&output).unwrap();
239+
assert_eq!(s.contains("newline_style"), true);
240+
assert_eq!(s.contains("use_small_heuristics"), true);
241+
}
242+
221243
// FIXME(#2183) these tests cannot be run in parallel because they use env vars
222244
// #[test]
223245
// fn test_as_not_nightly_channel() {

0 commit comments

Comments
 (0)