fix!: Use display_name rather than bin_name in version output

This commit is contained in:
Ed Page 2022-07-22 11:40:30 -05:00
parent 01a3ea425f
commit a842bd64a0
4 changed files with 5 additions and 12 deletions

View file

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

View file

@ -59,6 +59,6 @@ $ 03_04_subcommands --version
clap [..]
$ 03_04_subcommands add --version
03_04_subcommands[EXE]-add [..]
clap-add [..]
```

View file

@ -59,6 +59,6 @@ $ 03_04_subcommands --version
clap [..]
$ 03_04_subcommands add --version
03_04_subcommands-add [..]
clap-add [..]
```

View file

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