#How do I generate clap_mangen man pages from flags inside my project?
1 messages · Page 1 of 1 (latest)
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
Awesome. I really appreciate it
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
I've read https://doc.rust-lang.org/cargo/reference/build-scripts.html#build-dependencies and it seems like build.rs doesn't have access to my project or it's dependencies, which is where I have all the flags defined. Not sure how I should set this up. Anyone familiar?