Skip to content

Commit f4e631b

Browse files
Feature/manpage (#596)
This PR adds a build script to generate a man page using clap_mangen, as per this example: https://github.com/sondr3/clap-man-example/blob/main/build.rs I'm not sure what to actually do with the man file from here, I guess it's up to the packaging process to do something with it? See #69 (comment) Note I couldn't see a way to include the `DISPLAY` chunk names from the constant as we did before. They're now just hardcoded into the help and will require manually updating if the list changes. Closes #526 --------- Co-authored-by: Alejandro González <[email protected]>
1 parent 2c3321b commit f4e631b

9 files changed

+439
-360
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ target
44
*.out.png
55
/.idea
66
/node_modules
7+
/generated

Cargo.lock

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

Cargo.toml

+10
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.12"
8183
rustc_version = "0.4.0"
8284

8385
[features]
@@ -98,3 +100,11 @@ opt-level = 2
98100
lto = "fat"
99101
strip = "symbols"
100102
panic = "abort"
103+
104+
[package.metadata.deb]
105+
assets = [
106+
["target/release/oxipng", "usr/bin/", "755"],
107+
["generated/assets/oxipng.1", "usr/share/man/man1/", "644"],
108+
["README.md", "usr/share/doc/oxipng/", "644"],
109+
["CHANGELOG.md", "usr/share/doc/oxipng/", "644"],
110+
]

build.rs

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

0 commit comments

Comments
 (0)