Merge pull request #4566 from hitenkoku/fix/4565

removed {bin} variable from help_template
This commit is contained in:
Ed Page 2022-12-22 10:33:22 -06:00 committed by GitHub
commit 9242e1dd00
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 67 additions and 4 deletions

View file

@ -199,7 +199,7 @@ pub fn example10(c: &mut Criterion) {
}
pub fn example4_template(c: &mut Criterion) {
let mut cmd = app_example4().help_template("{bin} {version}\n{author}\n{about}\n\nUSAGE:\n {usage}\n\nOPTIONS:\n{options}\n\nARGS:\n{args}\n");
let mut cmd = app_example4().help_template("{name} {version}\n{author}\n{about}\n\nUSAGE:\n {usage}\n\nOPTIONS:\n{options}\n\nARGS:\n{args}\n");
c.bench_function("example4_template", |b| b.iter(|| build_help(&mut cmd)));
}

View file

@ -256,7 +256,7 @@ const USAGE: &str = "
rg [OPTIONS] --type-list";
const TEMPLATE: &str = "\
{bin} {version}
{name} {version}
{author}
{about}

View file

@ -1744,7 +1744,7 @@ impl Command {
/// Valid tags are:
///
/// * `{name}` - Display name for the (sub-)command.
/// * `{bin}` - Binary name.
/// * `{bin}` - Binary name.(deprecated)
/// * `{version}` - Version number.
/// * `{author}` - Author information.
/// * `{author-with-newline}` - Author followed by `\n`.
@ -1772,7 +1772,7 @@ impl Command {
/// # use clap::Command;
/// Command::new("myprog")
/// .version("1.0")
/// .help_template("{bin} ({version}) - {usage}")
/// .help_template("{name} ({version}) - {usage}")
/// # ;
/// ```
///

View file

@ -359,6 +359,13 @@ pub(crate) fn assert_app(cmd: &Command) {
cmd.get_name(),
"`{unified}` template variable was removed in clap3, use `{options}` instead"
);
#[cfg(feature = "unstable-v5")]
assert!(
!help_template.to_string().contains("{bin}"),
"Command {}: {}",
cmd.get_name(),
"`{bin}` template variable was removed in clap5, use `{name}` instead"
)
}
cmd._panic_on_missing_help(cmd.is_help_expected_set());

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,7 @@ Options:
-V, --version Print version information
";
#[cfg(not(feature = "unstable-v5"))]
let cmd = Command::new("ripgrep")
.version("0.5")
.override_usage(
@ -1057,6 +1058,26 @@ Options:
Usage: {usage}
Options:
{options}",
);
#[cfg(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(
"\
{name} {version}
Usage: {usage}
Options:
{options}",
);

View file

@ -2,6 +2,7 @@ use super::utils;
use clap::{arg, Command};
#[cfg(not(feature = "unstable-v5"))]
static EXAMPLE1_TMPL_S: &str = "{bin} {version}
{author}
{about}
@ -10,6 +11,16 @@ Usage: {usage}
{all-args}";
#[cfg(feature = "unstable-v5")]
static EXAMPLE1_TMPL_S: &str = "{name} {version}
{author}
{about}
Usage: {usage}
{all-args}";
#[cfg(not(feature = "unstable-v5"))]
static EXAMPLE1_TMPS_F: &str = "{bin} {version}
{author}
{about}
@ -23,6 +34,20 @@ Arguments:
Commands:
{subcommands}";
#[cfg(feature = "unstable-v5")]
static EXAMPLE1_TMPS_F: &str = "{name} {version}
{author}
{about}
Usage: {usage}
Options:
{options}
Arguments:
{positionals}
Commands:
{subcommands}";
static CUSTOM_TEMPL_HELP: &str = "MyApp 1.0
Kevin K. <kbknapp@gmail.com>
Does awesome things
@ -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",