Generate manpages for subcommands #3603
Replies: 3 comments 4 replies
-
This isn't the smoothest yet as both our man page generation is weak and it is using an under-developed part of the API. You need to at least use a private part of the API, |
Beta Was this translation helpful? Give feedback.
-
Just stumbled upon this same problem. It seems by now the hidden This is how I generate the man pages currently: 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)
} When having subcommands setup up like the following, it'll lose the information of the uppermost command (well, pretty much everything from the parent-parent name and upwards). Let's look at a simple example: #[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,
} This will result in the following commands as present in the
But the
Is there currently a way to get around this? Had a quick peek at the code, and it seems not? The issue seems to be, that the generator uses Also, should I open a separate issue ticket for this @epage? |
Beta Was this translation helpful? Give feedback.
-
Another issue with the suggested approach changing I am making this comment here as this approach was suggested for example as a correct solution here: #3629 (comment) |
Beta Was this translation helpful? Give feedback.
-
Maybe I'm missing something, but clap_mangen only seems to generate a manpage for the root command. I wanted additional manpages for each of the subcommands, like how git has manpages for git-status, git-checkout, etc. Here's the code I used to recursively generate those manpages, in case that's helpful to someone. It would be nice though if this were natively available in clap_mangen at some point because this is something that it seems like most projects would need.
I'm kind of new to Rust, so there might be improvements that could be made.
Beta Was this translation helpful? Give feedback.
All reactions