oxipng/build.rs
andrews05 f4e631bce7
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
https://github.com/shssoichiro/oxipng/issues/69#issuecomment-1963352536

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 <me@alegon.dev>
2024-03-18 12:28:52 +01:00

34 lines
726 B
Rust

use std::{
env,
fs::File,
io::{BufWriter, Error},
path::Path,
};
use clap_mangen::Man;
include!("src/cli.rs");
fn build_manpages(outdir: &Path) -> Result<(), Error> {
let app = build_command();
let file = Path::new(&outdir).join("oxipng.1");
let mut file = BufWriter::new(File::create(file)?);
Man::new(app).render(&mut file)?;
Ok(())
}
fn main() -> Result<(), Error> {
println!("cargo:rerun-if-changed=src/cli.rs");
println!("cargo:rerun-if-changed=src/display_chunks.rs");
// Create `generated/assets/` folder.
let path = env::current_dir()?.join("generated").join("assets");
std::fs::create_dir_all(&path).unwrap();
build_manpages(&path)?;
Ok(())
}