Repository: clap-rs/clap (rust)

Issue:
[clap_mangen] Subcommand references in man pages miss prefix
### Please complete the following tasks

- [X] I have searched the [discussions](https://github.com/clap-rs/clap/discussions)
- [X] I have searched the [open](https://github.com/clap-rs/clap/issues) and [rejected](https://github.com/clap-rs/clap/issues?q=is%3Aissue+label%3AS-wont-fix+is%3Aclosed) issues

### Rust Version

rustc 1.63.0 (4b91a6ea7 2022-08-08)

### Clap Version

v3.2.22 (clap_mangen v0.1.11)

### Minimal reproducible code

```rust
#[derive(Parser)]
#[clap(about, author, version)]
struct Opt {
    #[clap(subcommand)]
    cmd: Option<Command>,
}

#[derive(Subcommand)]
enum Command {
    Check {
        file: PathBuf,
    },
    Manpages {
        dir: PathBuf,
    },
    #[clap(subcommand)]
    Temp(TempCommand),
}

#[derive(Subcommand)]
enum TempCommand {
    TestA,
    TestB,
}
```


### Steps to reproduce the bug with the above code

Create a dir `temp` in the current pwd and run a basic app with the above setup with `cargo run -- manpages temp`. As implementation for creating the manpages I use the below code:

```rust
fn print_manpages(dir: &Path) -> Result<()> {
    fn print(dir: &Path, app: &App) -> Result<()> {
        // `get_display_name()` is `Some` for all instances, except the root.
        let name = app.get_display_name().unwrap_or_else(|| app.get_name());
        let mut out = File::create(dir.join(format!("{name}.1")))?;

        clap_mangen::Man::new(app.clone()).render(&mut out)?;
        out.flush()?;

        for sub in app.get_subcommands() {
            print(dir, sub)?;
        }

        Ok(())
    }

    let mut app = Opt::command();
    app.build();

    print(dir, &app)
}
```

### Actual Behaviour

In the end of the man pages, the direct subcommands are listed as additional man page files. The sum of all these references are as follows:


- `sample-check(1)`
- `sample-manpages(1)`
- `sample-temp(1)`
- `temp-test-a(1)` <-- missing sample- prefix
- `temp-test-b(1)` <-- missing sample- prefix


### Expected Behaviour

As seen above, the last two references miss the expected prefix. The actual existing file name is right, but the names inside the man pages are wrong. The expected names would be:


- `sample(1)`
- `sample-check(1)`
- `sample-manpages(1)`
- `sample-temp(1)`
- `sample-temp-test-a(1)`
- `sample-temp-test-b(1)`


### Additional Context

Originally mentioned in discussion https://github.com/clap-rs/clap/discussions/3603, now extracted here as issue.

### Debug Output

_No response_

Pull request description:
[clap_mangen]fix: use proper sub-command name in manpages
This Pr tries to fix #4231. It uses `get_display_name` instead of `get_name` in  clap_mangen as suggested [here](https://github.com/clap-rs/clap/discussions/3603#discussioncomment-3645485).

Patch:
diff --git a/clap_mangen/src/render.rs b/clap_mangen/src/render.rs
index 8a378fd5..88b9a6df 100644
--- a/clap_mangen/src/render.rs
+++ b/clap_mangen/src/render.rs
@@ -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()) {


Test patch:
diff --git a/clap_mangen/tests/roff.rs b/clap_mangen/tests/roff.rs
index 0c6d99db..223196c3 100644
--- a/clap_mangen/tests/roff.rs
+++ b/clap_mangen/tests/roff.rs
@@ -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());
+    }
+}
diff --git a/clap_mangen/tests/snapshots/sub_subcommand_help.roff b/clap_mangen/tests/snapshots/sub_subcommand_help.roff
new file mode 100644
index 00000000..674ee953
--- /dev/null
+++ b/clap_mangen/tests/snapshots/sub_subcommand_help.roff
@@ -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)