mirror of
https://github.com/clap-rs/clap
synced 2024-09-20 22:41:52 +00:00
Merge pull request #4255 from anshulrgoyal/master
[clap_mangen]fix: use proper sub-command name in manpages
This commit is contained in:
commit
d24e723bb4
3 changed files with 39 additions and 1 deletions
|
@ -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()) {
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
|
19
clap_mangen/tests/snapshots/sub_subcommand_help.roff
Normal file
19
clap_mangen/tests/snapshots/sub_subcommand_help.roff
Normal 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)
|
Loading…
Reference in a new issue