From a842bd64a08d27c11215cd95710a1bb8fea2c9c2 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Fri, 22 Jul 2022 11:40:30 -0500 Subject: [PATCH] fix!: Use display_name rather than bin_name in version output --- CHANGELOG.md | 1 + examples/tutorial_builder/03_04_subcommands.md | 2 +- examples/tutorial_derive/03_04_subcommands.md | 2 +- src/builder/command.rs | 12 ++---------- 4 files changed, 5 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dc5a939a..6b22b0d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - *(assert)* Always enforce that version is specified when the `ArgAction::Version` is used - *(assert)* Add missing `#[track_caller]`s to make it easier to debug asserts - *(help)* Use `Command::display_name` in the help title rather than `Command::bin_name` +- *(version)* Use `Command::display_name` rather than `Command::bin_name` - *(parser)* Assert on unknown args when using external subcommands (#3703) - *(parser)* Always fill in `""` argument for external subcommands (#3263) - *(derive)* Detect escaped external subcommands that look like built-in subcommands (#3703) diff --git a/examples/tutorial_builder/03_04_subcommands.md b/examples/tutorial_builder/03_04_subcommands.md index a94b12f1..6c94e35a 100644 --- a/examples/tutorial_builder/03_04_subcommands.md +++ b/examples/tutorial_builder/03_04_subcommands.md @@ -59,6 +59,6 @@ $ 03_04_subcommands --version clap [..] $ 03_04_subcommands add --version -03_04_subcommands[EXE]-add [..] +clap-add [..] ``` diff --git a/examples/tutorial_derive/03_04_subcommands.md b/examples/tutorial_derive/03_04_subcommands.md index 6f4147b1..41f449b2 100644 --- a/examples/tutorial_derive/03_04_subcommands.md +++ b/examples/tutorial_derive/03_04_subcommands.md @@ -59,6 +59,6 @@ $ 03_04_subcommands --version clap [..] $ 03_04_subcommands add --version -03_04_subcommands-add [..] +clap-add [..] ``` diff --git a/src/builder/command.rs b/src/builder/command.rs index adfefc47..5871c62f 100644 --- a/src/builder/command.rs +++ b/src/builder/command.rs @@ -4391,16 +4391,8 @@ To change `help`s short, call `cmd.arg(Arg::new(\"help\")...)`.", } else { self.version.or(self.long_version).unwrap_or("") }; - if let Some(bn) = self.bin_name.as_ref() { - if bn.contains(' ') { - // In case we're dealing with subcommands i.e. git mv is translated to git-mv - format!("{} {}\n", bn.replace(' ', "-"), ver) - } else { - format!("{} {}\n", &self.name[..], ver) - } - } else { - format!("{} {}\n", &self.name[..], ver) - } + let display_name = self.get_display_name().unwrap_or_else(|| self.get_name()); + format!("{} {}\n", display_name, ver) } pub(crate) fn format_group(&self, g: &Id) -> String {