Skip to content

Commit c28402a

Browse files
committed
config: Allow excluding config settings from --config-help output
1 parent 80db099 commit c28402a

File tree

1 file changed

+77
-62
lines changed

1 file changed

+77
-62
lines changed

src/config.rs

Lines changed: 77 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,18 @@ impl ConfigHelpItem {
186186
}
187187
}
188188

189+
/// Controls if a config field is printed in docs.
190+
enum ConfigDoc {
191+
/// Include in docs.
192+
Doc,
193+
/// Do not include in docs.
194+
#[allow(dead_code)]
195+
NoDoc,
196+
}
197+
use self::ConfigDoc::*;
198+
189199
macro_rules! create_config {
190-
($($i:ident: $ty:ty, $def:expr, $( $dstring:expr ),+ );+ $(;)*) => (
200+
($($doc:ident $i:ident: $ty:ty, $def:expr, $( $dstring:expr ),+ );+ $(;)*) => (
191201
#[derive(RustcDecodable, Clone)]
192202
pub struct Config {
193203
$(pub $i: $ty),+
@@ -253,21 +263,23 @@ macro_rules! create_config {
253263
}
254264
println!("Configuration Options:");
255265
$(
256-
let name_raw = stringify!($i);
257-
let mut name_out = String::with_capacity(max);
258-
for _ in name_raw.len()..max-1 {
259-
name_out.push(' ')
266+
if let ConfigDoc::Doc = $doc {
267+
let name_raw = stringify!($i);
268+
let mut name_out = String::with_capacity(max);
269+
for _ in name_raw.len()..max-1 {
270+
name_out.push(' ')
271+
}
272+
name_out.push_str(name_raw);
273+
name_out.push(' ');
274+
println!("{}{} Default: {:?}",
275+
name_out,
276+
<$ty>::get_variant_names(),
277+
$def);
278+
$(
279+
println!("{}{}", space_str, $dstring);
280+
)+
281+
println!("");
260282
}
261-
name_out.push_str(name_raw);
262-
name_out.push(' ');
263-
println!("{}{} Default: {:?}",
264-
name_out,
265-
<$ty>::get_variant_names(),
266-
$def);
267-
$(
268-
println!("{}{}", space_str, $dstring);
269-
)+
270-
println!("");
271283
)+
272284
}
273285
}
@@ -286,66 +298,69 @@ macro_rules! create_config {
286298
}
287299

288300
create_config! {
289-
verbose: bool, false, "Use verbose output";
290-
skip_children: bool, false, "Don't reformat out of line modules";
291-
max_width: usize, 100, "Maximum width of each line";
292-
ideal_width: usize, 80, "Ideal width of each line";
293-
tab_spaces: usize, 4, "Number of spaces per tab";
294-
fn_call_width: usize, 60,
301+
Doc verbose: bool, false, "Use verbose output";
302+
Doc skip_children: bool, false, "Don't reformat out of line modules";
303+
Doc max_width: usize, 100, "Maximum width of each line";
304+
Doc ideal_width: usize, 80, "Ideal width of each line";
305+
Doc tab_spaces: usize, 4, "Number of spaces per tab";
306+
Doc fn_call_width: usize, 60,
295307
"Maximum width of the args of a function call before falling back to vertical formatting";
296-
struct_lit_width: usize, 16,
308+
Doc struct_lit_width: usize, 16,
297309
"Maximum width in the body of a struct lit before falling back to vertical formatting";
298-
newline_style: NewlineStyle, NewlineStyle::Unix, "Unix or Windows line endings";
299-
fn_brace_style: BraceStyle, BraceStyle::SameLineWhere, "Brace style for functions";
300-
item_brace_style: BraceStyle, BraceStyle::SameLineWhere, "Brace style for structs and enums";
301-
impl_empty_single_line: bool, true, "Put empty-body implementations on a single line";
302-
fn_empty_single_line: bool, true, "Put empty-body functions on a single line";
303-
fn_single_line: bool, false, "Put single-expression functions on a single line";
304-
fn_return_indent: ReturnIndent, ReturnIndent::WithArgs,
310+
Doc newline_style: NewlineStyle, NewlineStyle::Unix, "Unix or Windows line endings";
311+
Doc fn_brace_style: BraceStyle, BraceStyle::SameLineWhere, "Brace style for functions";
312+
Doc item_brace_style: BraceStyle, BraceStyle::SameLineWhere,
313+
"Brace style for structs and enums";
314+
Doc impl_empty_single_line: bool, true, "Put empty-body implementations on a single line";
315+
Doc fn_empty_single_line: bool, true, "Put empty-body functions on a single line";
316+
Doc fn_single_line: bool, false, "Put single-expression functions on a single line";
317+
Doc fn_return_indent: ReturnIndent, ReturnIndent::WithArgs,
305318
"Location of return type in function declaration";
306-
fn_args_paren_newline: bool, true, "If function argument parenthesis goes on a newline";
307-
fn_args_density: Density, Density::Tall, "Argument density in functions";
308-
fn_args_layout: StructLitStyle, StructLitStyle::Visual, "Layout of function arguments";
309-
fn_arg_indent: BlockIndentStyle, BlockIndentStyle::Visual, "Indent on function arguments";
310-
type_punctuation_density: TypeDensity, TypeDensity::Wide,
319+
Doc fn_args_paren_newline: bool, true, "If function argument parenthesis goes on a newline";
320+
Doc fn_args_density: Density, Density::Tall, "Argument density in functions";
321+
Doc fn_args_layout: StructLitStyle, StructLitStyle::Visual, "Layout of function arguments";
322+
Doc fn_arg_indent: BlockIndentStyle, BlockIndentStyle::Visual, "Indent on function arguments";
323+
Doc type_punctuation_density: TypeDensity, TypeDensity::Wide,
311324
"Determines if '+' or '=' are wrapped in spaces in the punctuation of types";
312325
// Should we at least try to put the where clause on the same line as the rest of the
313326
// function decl?
314-
where_density: Density, Density::CompressedIfEmpty, "Density of a where clause";
327+
Doc where_density: Density, Density::CompressedIfEmpty, "Density of a where clause";
315328
// Visual will be treated like Tabbed
316-
where_indent: BlockIndentStyle, BlockIndentStyle::Tabbed, "Indentation of a where clause";
317-
where_layout: ListTactic, ListTactic::Vertical, "Element layout inside a where clause";
318-
where_pred_indent: BlockIndentStyle, BlockIndentStyle::Visual,
329+
Doc where_indent: BlockIndentStyle, BlockIndentStyle::Tabbed, "Indentation of a where clause";
330+
Doc where_layout: ListTactic, ListTactic::Vertical, "Element layout inside a where clause";
331+
Doc where_pred_indent: BlockIndentStyle, BlockIndentStyle::Visual,
319332
"Indentation style of a where predicate";
320-
where_trailing_comma: bool, false, "Put a trailing comma on where clauses";
321-
generics_indent: BlockIndentStyle, BlockIndentStyle::Visual, "Indentation of generics";
322-
struct_trailing_comma: SeparatorTactic, SeparatorTactic::Vertical,
333+
Doc where_trailing_comma: bool, false, "Put a trailing comma on where clauses";
334+
Doc generics_indent: BlockIndentStyle, BlockIndentStyle::Visual, "Indentation of generics";
335+
Doc struct_trailing_comma: SeparatorTactic, SeparatorTactic::Vertical,
323336
"If there is a trailing comma on structs";
324-
struct_lit_trailing_comma: SeparatorTactic, SeparatorTactic::Vertical,
337+
Doc struct_lit_trailing_comma: SeparatorTactic, SeparatorTactic::Vertical,
325338
"If there is a trailing comma on literal structs";
326-
struct_lit_style: StructLitStyle, StructLitStyle::Block, "Style of struct definition";
327-
struct_lit_multiline_style: MultilineStyle, MultilineStyle::PreferSingle,
339+
Doc struct_lit_style: StructLitStyle, StructLitStyle::Block, "Style of struct definition";
340+
Doc struct_lit_multiline_style: MultilineStyle, MultilineStyle::PreferSingle,
328341
"Multiline style on literal structs";
329-
enum_trailing_comma: bool, true, "Put a trailing comma on enum declarations";
330-
report_todo: ReportTactic, ReportTactic::Never,
342+
Doc enum_trailing_comma: bool, true, "Put a trailing comma on enum declarations";
343+
Doc report_todo: ReportTactic, ReportTactic::Never,
331344
"Report all, none or unnumbered occurrences of TODO in source file comments";
332-
report_fixme: ReportTactic, ReportTactic::Never,
345+
Doc report_fixme: ReportTactic, ReportTactic::Never,
333346
"Report all, none or unnumbered occurrences of FIXME in source file comments";
334-
chain_base_indent: BlockIndentStyle, BlockIndentStyle::Visual, "Indent on chain base";
335-
chain_indent: BlockIndentStyle, BlockIndentStyle::Visual, "Indentation of chain";
336-
reorder_imports: bool, false, "Reorder import statements alphabetically";
337-
single_line_if_else: bool, false, "Put else on same line as closing brace for if statements";
338-
format_strings: bool, true, "Format string literals where necessary";
339-
force_format_strings: bool, false, "Always format string literals";
340-
chains_overflow_last: bool, true, "Allow last call in method chain to break the line";
341-
take_source_hints: bool, true, "Retain some formatting characteristics from the source code";
342-
hard_tabs: bool, false, "Use tab characters for indentation, spaces for alignment";
343-
wrap_comments: bool, false, "Break comments to fit on the line";
344-
normalise_comments: bool, true, "Convert /* */ comments to // comments where possible";
345-
wrap_match_arms: bool, true, "Wrap multiline match arms in blocks";
346-
match_block_trailing_comma: bool, false,
347+
Doc chain_base_indent: BlockIndentStyle, BlockIndentStyle::Visual, "Indent on chain base";
348+
Doc chain_indent: BlockIndentStyle, BlockIndentStyle::Visual, "Indentation of chain";
349+
Doc reorder_imports: bool, false, "Reorder import statements alphabetically";
350+
Doc single_line_if_else: bool, false,
351+
"Put else on same line as closing brace for if statements";
352+
Doc format_strings: bool, true, "Format string literals where necessary";
353+
Doc force_format_strings: bool, false, "Always format string literals";
354+
Doc chains_overflow_last: bool, true, "Allow last call in method chain to break the line";
355+
Doc take_source_hints: bool, true,
356+
"Retain some formatting characteristics from the source code";
357+
Doc hard_tabs: bool, false, "Use tab characters for indentation, spaces for alignment";
358+
Doc wrap_comments: bool, false, "Break comments to fit on the line";
359+
Doc normalise_comments: bool, true, "Convert /* */ comments to // comments where possible";
360+
Doc wrap_match_arms: bool, true, "Wrap multiline match arms in blocks";
361+
Doc match_block_trailing_comma: bool, false,
347362
"Put a trailing comma after a block based match arm (non-block arms are not affected)";
348-
match_wildcard_trailing_comma: bool, true, "Put a trailing comma after a wildcard arm";
349-
write_mode: WriteMode, WriteMode::Replace,
363+
Doc match_wildcard_trailing_comma: bool, true, "Put a trailing comma after a wildcard arm";
364+
Doc write_mode: WriteMode, WriteMode::Replace,
350365
"What Write Mode to use when none is supplied: Replace, Overwrite, Display, Diff, Coverage";
351366
}

0 commit comments

Comments
 (0)