Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[clap_mangen] Subcommand references in man pages miss prefix #4231

Closed
2 tasks done
dnaka91 opened this issue Sep 19, 2022 · 3 comments · Fixed by #4255
Closed
2 tasks done

[clap_mangen] Subcommand references in man pages miss prefix #4231

dnaka91 opened this issue Sep 19, 2022 · 3 comments · Fixed by #4255
Labels
A-man Area: man generator C-bug Category: Updating dependencies E-easy Call for participation: Experience needed to fix: Easy / not much E-help-wanted Call for participation: Help is requested to fix this issue.

Comments

@dnaka91
Copy link
Contributor

dnaka91 commented Sep 19, 2022

Please complete the following tasks

Rust Version

rustc 1.63.0 (4b91a6ea7 2022-08-08)

Clap Version

v3.2.22 (clap_mangen v0.1.11)

Minimal reproducible code

#[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:

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 #3603, now extracted here as issue.

Debug Output

No response

@dnaka91 dnaka91 added the C-bug Category: Updating dependencies label Sep 19, 2022
@epage epage added E-easy Call for participation: Experience needed to fix: Easy / not much A-man Area: man generator E-help-wanted Call for participation: Help is requested to fix this issue. labels Sep 19, 2022
@BoostCookie
Copy link

The man pages have correct file names now, but the content of a page only shows the subcommand name under NAME and SYNOPSIS.
I would expect it to look like man git-commit

NAME
       git-commit - Record changes to the repository

SYNOPSIS
       git commit [-a | --interactive | --patch] [-s] [-v] [-u<mode>] [--amend]
       ...

But clap_mangen would generate the following

NAME
       commit - Record changes to the repository

SYNOPSIS
       commit [-a | --interactive | --patch] [-s] [-v] [-u<mode>] [--amend]
       ...

So the parent command is missing in the page.

@Will-Shanks
Copy link
Contributor

I'm running into the same problem as @BoostCookie, would it make sense to reopen this or should I submit a new issue @epage? I'd be happy to work on a PR if this change is agreeable.

@epage
Copy link
Member

epage commented Jan 12, 2024

Feel free

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-man Area: man generator C-bug Category: Updating dependencies E-easy Call for participation: Experience needed to fix: Easy / not much E-help-wanted Call for participation: Help is requested to fix this issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants