diff --git a/Cargo.lock b/Cargo.lock index 958cd27..d716e69 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -272,6 +272,16 @@ version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1" +[[package]] +name = "clap_mangen" +version = "0.2.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43144ab702c764b0a3ecda5ecd2aba2e6874d8de4b9f56930bbb1e88fcecd84a" +dependencies = [ + "clap", + "roff", +] + [[package]] name = "colorchoice" version = "1.0.0" @@ -903,6 +913,12 @@ dependencies = [ "bitflags 1.3.2", ] +[[package]] +name = "roff" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b833d8d034ea094b1ea68aa6d5c740e0d04bad9d16568d08ba6f76823a114316" + [[package]] name = "rust-embed" version = "6.8.1" @@ -1508,6 +1524,7 @@ dependencies = [ "clap", "clap-markdown", "clap-verbosity-flag", + "clap_mangen", "log", "ocli", "serde_yaml", diff --git a/Cargo.toml b/Cargo.toml index c3ed6f4..ee54134 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" @@ -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" diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..a797daf --- /dev/null +++ b/build.rs @@ -0,0 +1,24 @@ +include!("src/cli.rs"); + +fn main() -> std::io::Result<()> { + generate_man::()?; + Ok(()) +} + +fn generate_man() -> 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 = Default::default(); + man.render(&mut buffer)?; + std::fs::write(fname, buffer)?; + Ok(()) +}