#How do I generate clap_mangen man pages from flags inside my project?

1 messages · Page 1 of 1 (latest)

indigo steeple
#

It seems that you are suppsosed to recreate the structure of your parser in main() while only having access to clap and clap_mangen

indigo steeple
#

build.rs```rust
/// Required to convert a derive to Command
use clap::CommandFactory;

/// Import the module that has the clap derive struct
#[path = "src/config/args.rs"]
mod args;

/// Bring that derive struct in scope
use args::Args;

fn main() -> std::io::Result<()> {
// Place the docs into a normal directory, not some
// target subfolder
let out_dir = std::path::PathBuf::from("doc/man");

// If you have derive API then use ::command()
// and import CommandFactory
// otherwise just obtain the Command
let cmd = Args::command();

// the rest is from the example
let man = clap_mangen::Man::new(cmd);
let mut buffer: Vec<u8> = Default::default();
man.render(&mut buffer)?;
std::fs::write(out_dir.join("manpage.roff"), buffer)?;

Ok(())

}
**Cargo.toml**toml
...
[build-dependencies]
clap_mangen = "0.2.6"
[build-dependencies.clap]
version = "4.0"
features = [ "derive" ] # if you use #[derive(Parser)]

#

@ionic shell I did it! idk if you got notified so there you go

indigo steeple
#

The only thing i noticed is that the man pages that it generates are just really crap for my usecase

#

like it does not know how to deal with subcommands

#

among other issues

ionic shell