• Home
Name
Date
Size
#Lines
LOC

..--

examples/12-May-2024-3933

src/12-May-2024-624489

tests/12-May-2024-786726

CHANGELOG.mdD12-May-20242.8 KiB9459

CONTRIBUTING.mdD12-May-2024126 42

Cargo.tomlD12-May-20241.5 KiB4538

LICENSE-APACHED12-May-202411.1 KiB202169

LICENSE-MITD12-May-20241.1 KiB2217

README.mdD12-May-20241.9 KiB5437

README.md

1<!-- omit in TOC -->
2# clap_mangen
3
4> **Manpage generation for `clap`**
5
6[![Crates.io](https://img.shields.io/crates/v/clap_mangen?style=flat-square)](https://crates.io/crates/clap_mangen)
7[![Crates.io](https://img.shields.io/crates/d/clap_mangen?style=flat-square)](https://crates.io/crates/clap_mangen)
8[![License](https://img.shields.io/badge/license-Apache%202.0-blue?style=flat-square)](https://github.com/clap-rs/clap/blob/clap_mangen-v0.2.7/LICENSE-APACHE)
9[![License](https://img.shields.io/badge/license-MIT-blue?style=flat-square)](https://github.com/clap-rs/clap/blob/clap_mangen-v0.2.7/LICENSE-MIT)
10
11Dual-licensed under [Apache 2.0](LICENSE-APACHE) or [MIT](LICENSE-MIT).
12
131. [About](#about)
142. [API Reference](https://docs.rs/clap_mangen)
153. [Questions & Discussions](https://github.com/clap-rs/clap/discussions)
164. [CONTRIBUTING](https://github.com/clap-rs/clap/blob/clap_mangen-v0.2.7/clap_mangen/CONTRIBUTING.md)
175. [Sponsors](https://github.com/clap-rs/clap/blob/clap_mangen-v0.2.7/README.md#sponsors)
18
19## About
20
21Generate [ROFF](https://en.wikipedia.org/wiki/Roff_(software)) from a `clap::Command`.
22
23### Example
24
25We're going to assume you want to generate your man page as part of your
26development rather than your shipped program having a flag to generate it.
27
28In your `Cargo.toml`:
29```toml
30[build-dependencies]
31clap_mangen = "0.1"
32```
33
34In your `build.rs`:
35```rust,no_run
36fn main() -> std::io::Result<()> {
37    let out_dir = std::path::PathBuf::from(std::env::var_os("OUT_DIR").ok_or(std::io::ErrorKind::NotFound)?);
38
39    let cmd = clap::Command::new("mybin")
40        .arg(clap::arg!(-n --name <NAME>))
41        .arg(clap::arg!(-c --count <NUM>));
42
43    let man = clap_mangen::Man::new(cmd);
44    let mut buffer: Vec<u8> = Default::default();
45    man.render(&mut buffer)?;
46
47    std::fs::write(out_dir.join("mybin.1"), buffer)?;
48
49    Ok(())
50}
51```
52
53Tip: Consider a [cargo xtask](https://github.com/matklad/cargo-xtask) instead of a `build.rs` to reduce build costs.
54