Skip to content

Commit

Permalink
fix!: Use display_name rather than bin_name in version output
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Jul 22, 2022
1 parent 01a3ea4 commit a842bd6
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion examples/tutorial_builder/03_04_subcommands.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@ $ 03_04_subcommands --version
clap [..]

$ 03_04_subcommands add --version
03_04_subcommands[EXE]-add [..]
clap-add [..]

```
2 changes: 1 addition & 1 deletion examples/tutorial_derive/03_04_subcommands.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@ $ 03_04_subcommands --version
clap [..]

$ 03_04_subcommands add --version
03_04_subcommands-add [..]
clap-add [..]

```
12 changes: 2 additions & 10 deletions src/builder/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit a842bd6

Please sign in to comment.