fix(help_template): Added cfg

This commit is contained in:
DastInDark 2022-12-22 00:47:53 +09:00
parent a7a8241487
commit c6058dee6e
3 changed files with 56 additions and 0 deletions

View file

@ -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();
}

View file

@ -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(

View file

@ -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. <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",