Skip to content

Commit

Permalink
feat(help): Expose clap's indentation to help_template
Browse files Browse the repository at this point in the history
This will make it easier for help templates to be consistent with clap
  • Loading branch information
epage committed Aug 31, 2022
1 parent 803d87b commit 439c9e7
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions src/builder/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`].
///
Expand Down
17 changes: 11 additions & 6 deletions src/output/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion tests/builder/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}";

Expand Down
2 changes: 1 addition & 1 deletion tests/derive/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}";

Expand Down

0 comments on commit 439c9e7

Please sign in to comment.