mirror of
https://github.com/clap-rs/clap
synced 2025-03-03 14:57:13 +00:00
Merge pull request #4566 from hitenkoku/fix/4565
removed {bin} variable from help_template
This commit is contained in:
commit
9242e1dd00
7 changed files with 67 additions and 4 deletions
|
@ -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)));
|
||||
}
|
||||
|
||||
|
|
|
@ -256,7 +256,7 @@ const USAGE: &str = "
|
|||
rg [OPTIONS] --type-list";
|
||||
|
||||
const TEMPLATE: &str = "\
|
||||
{bin} {version}
|
||||
{name} {version}
|
||||
{author}
|
||||
{about}
|
||||
|
||||
|
|
|
@ -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}")
|
||||
/// # ;
|
||||
/// ```
|
||||
///
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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}",
|
||||
);
|
||||
|
|
|
@ -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",
|
||||
|
|
Loading…
Add table
Reference in a new issue