macro_rules! sections {
() => { ... };
($($rest:tt)*) => { ... };
}Expand description
Macro to declare a list of help sections. This can be passed to
Help to print it.
There are three kinds of sections:
-
Normal sections, wrapped in square brackets. Refer to the
textmacro for the syntax. Example:["test" c:"cyan" R!"bold red"]Each section is terminated by a line break.
-
Named sections. Example:
"Usage" { ["section 1"] ["section 2"] }Named sections are always preceded by a blank line. Child sections are indented with 4 spaces.
-
Tables. Example:
table Auto { "argument 1" => { ["help for argument 1"] } "argument 2" => { ["help for argument 2"] ["and some more help!"] } }With short help, this is rendered as
argument 1 help for argument 1 argument 2 help for argument 2 and some more help!With long help, this is rendered as
argument 1 help for argument 1 argument 2 help for argument 2 and some more help!The argument name (left column) must be a string literal. It is displayed in color.
The
tablekeyword must be followed by eitherAutoorCompact. IfCompactis used, then the compact format is used for both the short and long help. IfAutois used, the compact format is used for short help and the longer format is used for long help.
Beyond that, each section can be preceded by Short or Long. By default,
sections are included both in the long and short help. With the Short
modifier, it is only shown in the short help, and sections preceded by
Long only appear in the long help. Example:
sections!(
Short ["Short help text"]
Long ["This is more detailed help text"]
["This is shown either way"]
table Auto {
"argument 1" => {
["description"]
Long ["Further details only shown in long help"]
}
"argument 2" => {
Long ["This argument isn't shown in the short help"]
}
}
// table only shown in long help:
Long table Compact {}
Long "MORE DETAILS" {
["named section only shown in long help"]
}
);You can factor parts of the help message into variables, and include them in the sections! macro:
-
A single section is included by wrapping it in
{}:const FOO: HelpSection = HelpSection::Text(sections![]); Help(sections![ ["Included section:"] {FOO} ]); -
Content of named sections and table rows is included by replacing the
{...}with the variable name:const FOO: &[HelpSection] = sections![ ["First line"] ["Second line"] ]; Help(sections![ "Named section" FOO table Auto { "Foo" => FOO } ]);