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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct title,name and synopsis in generated man pages for subcommands #5301

Merged
merged 2 commits into from
Jan 29, 2024

Conversation

Will-Shanks
Copy link
Contributor

@Will-Shanks Will-Shanks commented Jan 13, 2024

Print the "full" command in the name,title, and synopsis of subcommand man pages. Currently if clap was to generate a man page for git add the title and name would be simply add, not git-add like expected, and the synopsis would be add <args> not git add <args>

  • This PR changes this to obtain the title and name the same way as the subcommand names list in a man page, which was fixed by [clap_mangen]fix: use proper sub-command name in manpages聽#4255
  • To obtain the proper usage string (ex: git add not git-add) I believe we want Command.usage_name, but it is private and the only way I could find to obtain it is via Command.render_usage() which unfortunately forces an unnecessary clone. This also causes duplication of positional arguments (as can be seen below with <COMMAND> (the struct name) and <subcommands> both appearing in the synopsis. Suggestions on how to fix that are appreciated. Fixed thanks to @EdJoPaTo suggestions 馃帀

Some minimal code to generate a cli with multiple sub (and subsub) commands to reproduce this can be found in my fork here

Additional context can be found in #4231

example (command = mrc temp from my linked test code)
Before:

temp(1)    General Commands Manual    temp(1)

NAME
       temp

SYNOPSIS
       temp [-h|--help] <subcommands>

After:

mrc-temp(1)    General Commands Manual    mrc-temp(1)

NAME
       mrc-temp

SYNOPSIS
       mrc temp [-h|--help] <subcommands>

Print the full command, instead of just the last subcommand in the man
page. ex for `git add` print `git-add` instead of simply `add` as the
title and name. For the synopsis print the usage string, so `git add`
Copy link
Contributor

@EdJoPaTo EdJoPaTo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Came across the same issue and found the PR which handles this nearly as expected. I have some thoughts to improve it (and hopefully get it merged sooner than later).

As the CI highlights (cargo test): tests/snapshots/sub_subcommand_help.roff needs an update. (Likely after the synopsis works correctly)

clap_mangen/src/render.rs Outdated Show resolved Hide resolved
clap_mangen/src/render.rs Outdated Show resolved Hide resolved
@Will-Shanks
Copy link
Contributor Author

Thanks to @EdJoPaTo's suggestions all tests are now passing, I also updated the top comment with the new man page before/after.

@epage
Copy link
Member

epage commented Jan 29, 2024

Thanks!

@epage epage merged commit 040ff6a into clap-rs:master Jan 29, 2024
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants