Merge pull request #4255 from anshulrgoyal/master

[clap_mangen]fix: use proper sub-command name in manpages
This commit is contained in:
Ed Page 2022-09-29 13:07:18 -05:00 committed by GitHub
commit d24e723bb4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 1 deletions

View file

@ -220,7 +220,12 @@ pub(crate) fn subcommands(roff: &mut Roff, cmd: &clap::Command, section: &str) {
for sub in cmd.get_subcommands().filter(|s| !s.is_hide_set()) {
roff.control("TP", []);
let name = format!("{}-{}({})", cmd.get_name(), sub.get_name(), section);
let name = format!(
"{}-{}({})",
cmd.get_display_name().unwrap_or_else(|| cmd.get_name()),
sub.get_name(),
section
);
roff.text([roman(&name)]);
if let Some(about) = sub.get_about().or_else(|| sub.get_long_about()) {

View file

@ -69,3 +69,17 @@ fn possible_values() {
let cmd = common::possible_values_command(name);
common::assert_matches_path("tests/snapshots/possible_values.bash.roff", cmd);
}
#[test]
fn sub_subcommands_help() {
let name = "my-app";
let mut cmd = common::sub_subcommands_command(name);
cmd.build();
let cmd = cmd
.get_subcommands()
.find(|cmd| cmd.get_display_name() == Some("my-app-help"));
assert!(cmd.is_some(), "help subcommand not found in command");
if let Some(cmd) = cmd {
common::assert_matches_path("tests/snapshots/sub_subcommand_help.roff", cmd.clone());
}
}

View file

@ -0,0 +1,19 @@
.ie /n(.g .ds Aq /(aq
.el .ds Aq '
.TH help 1 "help "
.SH NAME
help /- Print this message or the help of the given subcommand(s)
.SH SYNOPSIS
/fBhelp/fR [/fIsubcommands/fR]
.SH DESCRIPTION
Print this message or the help of the given subcommand(s)
.SH SUBCOMMANDS
.TP
my/-app/-help/-test(1)
tests things
.TP
my/-app/-help/-some_cmd(1)
top level subcommand
.TP
my/-app/-help/-help(1)
Print this message or the help of the given subcommand(s)