ouch/build.rs
2022-02-13 10:38:57 +01:00

27 lines
697 B
Rust

use std::{env, fs::create_dir_all};
use clap::{ArgEnum, IntoApp};
use clap_complete::{generate_to, Shell};
include!("src/opts.rs");
fn main() {
println!("cargo:rerun-if-env-changed=GEN_COMPLETIONS");
if env::var_os("GEN_COMPLETIONS") != Some("1".into()) {
return;
}
let out = &env::var_os("OUCH_COMPLETIONS_DIR")
.map(|path| PathBuf::from(&path))
.or_else(|| env::var_os("OUT_DIR").map(|path| PathBuf::from(&path)).map(|path| path.join("completions")))
.unwrap();
create_dir_all(out).unwrap();
let app = &mut Opts::into_app();
for shell in Shell::value_variants() {
generate_to(*shell, app, "ouch", out).unwrap();
}
}