Skip to main content

build_tools/
lib.rs

1use std::process::Command;
2use which::which;
3
4#[cfg(not(target_os = "windows"))]
5const DEFAULT_TARGET_DIR: &str = "../../target/release/assets";
6
7pub fn build_manpage(manpage: &str, source: &str) {
8    match which("asciidoctor") {
9        Err(why) => eprintln!("couldn't compile asciidoctor: {}", why),
10        Ok(command) => {
11            let target_dir = match std::env::var("CARGO_TARGET_DIR") {
12                Ok(dir) => dir,
13                _ => DEFAULT_TARGET_DIR.to_string(),
14            };
15
16            let result = Command::new(command)
17                .arg("-b")
18                .arg("manpage")
19                .arg("-o")
20                .arg(format!("{}/{}", target_dir, manpage))
21                .arg(format!("docs/{}", source))
22                .output()
23                .expect("asciidoctor failed");
24
25            if result.status.success() {
26                Command::new("gzip")
27                    .arg(format!("{}/{}", target_dir, manpage))
28                    .output()
29                    .expect("Fail for gzip running");
30            }
31        }
32    };
33}