Skip to content

Commit

Permalink
fix(help_template): Added cfg
Browse files Browse the repository at this point in the history
  • Loading branch information
hitenkoku committed Dec 21, 2022
1 parent a7a8241 commit c6058de
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/output/help_template.rs
Expand Up @@ -137,6 +137,7 @@ impl<'cmd, 'writer> HelpTemplate<'cmd, 'writer> {
"name" => {
self.write_display_name();
}
#[cfg(not(feature = "unstable-v5"))]
"bin" => {
self.write_bin_name();
}
Expand Down
21 changes: 21 additions & 0 deletions tests/builder/help.rs
Expand Up @@ -1042,6 +1042,27 @@ Options:
-V, --version Print version information
";

#[cfg(not(feature = "unstable-v5"))]
let cmd = Command::new("ripgrep")
.version("0.5")
.override_usage(
"\
rg [OPTIONS] <pattern> [<path> ...]
rg [OPTIONS] [-e PATTERN | -f FILE ]... [<path> ...]
rg [OPTIONS] --files [<path> ...]
rg [OPTIONS] --type-list",
)
.help_template(
"\
{bin} {version}
Usage: {usage}
Options:
{options}",
);

#[cfg(feature = "unstable-v5")]
let cmd = Command::new("ripgrep")
.version("0.5")
.override_usage(
Expand Down
34 changes: 34 additions & 0 deletions tests/builder/template_help.rs
Expand Up @@ -2,6 +2,16 @@ use super::utils;

use clap::{arg, Command};

#[cfg(not(feature = "unstable-v5"))]
static EXAMPLE1_TMPL_S: &str = "{bin} {version}
{author}
{about}
Usage: {usage}
{all-args}";

#[cfg(feature = "unstable-v5")]
static EXAMPLE1_TMPL_S: &str = "{name} {version}
{author}
{about}
Expand All @@ -10,6 +20,21 @@ Usage: {usage}
{all-args}";

#[cfg(not(feature = "unstable-v5"))]
static EXAMPLE1_TMPS_F: &str = "{bin} {version}
{author}
{about}
Usage: {usage}
Options:
{options}
Arguments:
{positionals}
Commands:
{subcommands}";

#[cfg(feature = "unstable-v5")]
static EXAMPLE1_TMPS_F: &str = "{name} {version}
{author}
{about}
Expand Down Expand Up @@ -105,11 +130,20 @@ fn template_unknowntag() {

#[test]
fn template_author_version() {
#[cfg(not(feature = "unstable-v5"))]
let cmd = Command::new("MyApp")
.version("1.0")
.author("Kevin K. <kbknapp@gmail.com>")
.about("Does awesome things")
.help_template("{author}\n{version}\n{about}\n{bin}");

#[cfg(feature = "unstable-v5")]
let cmd = Command::new("MyApp")
.version("1.0")
.author("Kevin K. <kbknapp@gmail.com>")
.about("Does awesome things")
.help_template("{author}\n{version}\n{about}\n{name}");

utils::assert_output(
cmd,
"MyApp --help",
Expand Down

0 comments on commit c6058de

Please sign in to comment.