Skip to content

Commit 9ef612b

Browse files
committed
Add build script for man generation
1 parent 08ea215 commit 9ef612b

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

Cargo.lock

+17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ features = ["png"]
7878
version = "0.24.6"
7979

8080
[build-dependencies]
81+
clap = "4.3.8"
82+
clap_mangen = "0.2.20"
8183
rustc_version = "0.4.0"
8284

8385
[features]

build.rs

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
use clap_mangen::Man;
2+
use std::{env, fs::File, io::Error, path::Path};
3+
4+
include!("src/cli.rs");
5+
6+
fn build_manpages(outdir: &Path) -> Result<(), Error> {
7+
let app = build_command();
8+
9+
let file = Path::new(&outdir).join("oxipng.1");
10+
let mut file = File::create(file)?;
11+
12+
Man::new(app).render(&mut file)?;
13+
14+
Ok(())
15+
}
16+
17+
fn main() -> Result<(), Error> {
18+
println!("cargo:rerun-if-changed=src/cli.rs");
19+
println!("cargo:rerun-if-changed=man");
20+
21+
let outdir = match env::var_os("OUT_DIR") {
22+
None => return Ok(()),
23+
Some(outdir) => outdir,
24+
};
25+
26+
// Create `target/assets/` folder.
27+
let out_path = PathBuf::from(outdir);
28+
let mut path = out_path.ancestors().nth(4).unwrap().to_owned();
29+
path.push("assets");
30+
std::fs::create_dir_all(&path).unwrap();
31+
32+
build_manpages(&path)?;
33+
34+
Ok(())
35+
}

0 commit comments

Comments
 (0)