build-tools 0.1.2

Common tools for project building support
Documentation
use std::process::Command;
use which::which;

const DEFAULT_TARGET_DIR: &str = "../../target/release/assets";

pub fn build_manpage(manpage: &str, source: &str) {
    match which("asciidoctor") {
        Err(why) => eprintln!("couldn't compile asciidoctor: {}", why),
        Ok(command) => {
            let target_dir = match std::env::var("CARGO_TARGET_DIR") {
                Ok(dir) => dir,
                _ => DEFAULT_TARGET_DIR.to_string(),
            };

            let result = Command::new(command)
                .arg("-b")
                .arg("manpage")
                .arg("-o")
                .arg(format!("{}/{}", target_dir, manpage))
                .arg(format!("docs/{}", source))
                .output()
                .expect("asciidoctor failed");

            if result.status.success() {
                Command::new("gzip")
                    .arg(format!("{}/{}", target_dir, manpage))
                    .output()
                    .expect("Fail for gzip running");
            }
        }
    };
}