feat(help): Expose clap's indentation to help_template

This will make it easier for help templates to be consistent with clap
This commit is contained in:
Ed Page 2022-08-31 15:42:59 -05:00
parent 803d87b193
commit 439c9e7a91
5 changed files with 15 additions and 8 deletions

View file

@ -74,6 +74,7 @@ Deprecated
- Added `TypedValueParser::map` to make it easier to reuse existing value parsers
- *(error)* `Error::apply` for changing the formatter for dropping binary size
- *(help)* Show `PossibleValue::help` in long help (`--help`) (#3312)
- *(help)* New `{tab}` variable for `Command::help_template`
### Fixes

View file

@ -1706,6 +1706,7 @@ impl Command {
/// * `{options}` - Help for options.
/// * `{positionals}` - Help for positional arguments.
/// * `{subcommands}` - Help for subcommands.
/// * `{tag}` - Standard tab sized used within clap
/// * `{after-help}` - Help from [`Command::after_help`] or [`Command::after_long_help`].
/// * `{before-help}` - Help from [`Command::before_help`] or [`Command::before_long_help`].
///

View file

@ -31,15 +31,17 @@ pub(crate) struct Help<'cmd, 'writer> {
// Public Functions
impl<'cmd, 'writer> Help<'cmd, 'writer> {
const DEFAULT_TEMPLATE: &'static str = "\
{before-help}{about-with-newline}\n\
{usage-heading}\n {usage}\n\
\n\
{all-args}{after-help}\
{before-help}{about-with-newline}
{usage-heading}
{tab}{usage}
{all-args}{after-help}\
";
const DEFAULT_NO_ARGS_TEMPLATE: &'static str = "\
{before-help}{about-with-newline}\n\
{usage-heading}\n {usage}{after-help}\
{before-help}{about-with-newline}
{usage-heading}
{tab}{usage}{after-help}\
";
/// Create a new `Help` instance.
@ -186,6 +188,9 @@ impl<'cmd, 'writer> Help<'cmd, 'writer> {
"subcommands" => {
self.write_subcommands(self.cmd);
}
"tab" => {
self.none(TAB);
}
"after-help" => {
self.write_after_help();
}

View file

@ -9,7 +9,7 @@ pub const FULL_TEMPLATE: &str = "\
{before-help}{name} {version}
{author-with-newline}{about-with-newline}
{usage-heading}
{usage}
{tab}{usage}
{all-args}{after-help}";

View file

@ -11,7 +11,7 @@ pub const FULL_TEMPLATE: &str = "\
{before-help}{name} {version}
{author-with-newline}{about-with-newline}
{usage-heading}
{usage}
{tab}{usage}
{all-args}{after-help}";