Skip to content

Commit

Permalink
generate the doc with clap_mangen
Browse files Browse the repository at this point in the history
  • Loading branch information
glehmann committed Feb 2, 2024
1 parent 696b966 commit 711e6d4
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ base64 = "0.21.7"
clap = { version = "4.4.18", features = ["derive", "env", "wrap_help"] }
clap-markdown = "0.1.3"
clap-verbosity-flag = "2.1.2"
clap_mangen = "0.2.18"
log = "0.4.20"
ocli = "0.1.1"
serde_yaml = "0.9.31"
Expand All @@ -28,6 +29,12 @@ tempfile = "3.9.0"
thiserror = "1.0.56"
treediff = { git = "https://github.com/glehmann/treediff-rs.git", branch = "serde-yaml-09", features = ["with-serde-yaml"] }

[build-dependencies]
clap = { version = "4.4.18", features = ["derive", "env", "wrap_help"] }
clap-markdown = "0.1.3"
clap-verbosity-flag = "2.1.2"
clap_mangen = "0.2.18"

[profile.release]
strip = "symbols"
opt-level = "z"
Expand Down
24 changes: 24 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
include!("src/cli.rs");

fn main() -> std::io::Result<()> {
generate_man::<Cli>()?;
Ok(())
}

fn generate_man<C: clap::CommandFactory>() -> std::io::Result<()> {
let command = C::command();
let out_dir =
std::path::PathBuf::from(std::env::var_os("OUT_DIR").ok_or(std::io::ErrorKind::NotFound)?);
let name = command.get_name();
let name = if name == "yage" {
"yage.1".to_owned()
} else {
format!("yage-{}.1", command.get_name())
};
let fname = out_dir.join(name);
let man = clap_mangen::Man::new(command);
let mut buffer: Vec<u8> = Default::default();
man.render(&mut buffer)?;
std::fs::write(fname, buffer)?;
Ok(())
}

0 comments on commit 711e6d4

Please sign in to comment.