From c6058dee6ed463e4f8de2c5c76c63eb576ca8cbe Mon Sep 17 00:00:00 2001 From: DastInDark <2350416+hitenkoku@users.noreply.github.com> Date: Thu, 22 Dec 2022 00:47:53 +0900 Subject: [PATCH] fix(help_template): Added cfg --- src/output/help_template.rs | 1 + tests/builder/help.rs | 21 +++++++++++++++++++++ tests/builder/template_help.rs | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+) diff --git a/src/output/help_template.rs b/src/output/help_template.rs index 3db80da7be6..6fe9db1b4a7 100644 --- a/src/output/help_template.rs +++ b/src/output/help_template.rs @@ -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(); } diff --git a/tests/builder/help.rs b/tests/builder/help.rs index ce1c1156966..dbd8084a9b4 100644 --- a/tests/builder/help.rs +++ b/tests/builder/help.rs @@ -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] [ ...] + rg [OPTIONS] [-e PATTERN | -f FILE ]... [ ...] + rg [OPTIONS] --files [ ...] + 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( diff --git a/tests/builder/template_help.rs b/tests/builder/template_help.rs index 5ca017ab338..4d305a24490 100644 --- a/tests/builder/template_help.rs +++ b/tests/builder/template_help.rs @@ -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} @@ -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} @@ -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. ") + .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. ") .about("Does awesome things") .help_template("{author}\n{version}\n{about}\n{name}"); + utils::assert_output( cmd, "MyApp --help",