40 lines
1.2 KiB
Rust
40 lines
1.2 KiB
Rust
use std::path::PathBuf;
|
|
|
|
use clap::{ArgEnum, CommandFactory};
|
|
use clap_complete::{generate_to, Shell};
|
|
|
|
include!("src/cli.rs");
|
|
|
|
fn main() -> std::io::Result<()> {
|
|
let mut cli = Cli::command();
|
|
|
|
if let Some(completions_dir) = std::env::var_os("PESHMING_COMPLETIONS_DIR") {
|
|
let completions_dir: PathBuf = completions_dir.into();
|
|
|
|
std::fs::create_dir_all(&completions_dir)
|
|
.expect("Could not create shell completions output folder.");
|
|
|
|
for shell in Shell::value_variants() {
|
|
generate_to(*shell, &mut cli, "peshming", &completions_dir).unwrap_or_else(|err| {
|
|
panic!(
|
|
"Failed to generate shell completions for {}: {}.",
|
|
shell, err
|
|
)
|
|
});
|
|
}
|
|
}
|
|
|
|
if let Some(man_dir) = std::env::var_os("PESHMING_MAN_DIR") {
|
|
let man_dir: PathBuf = man_dir.into();
|
|
|
|
std::fs::create_dir_all(&man_dir).expect("Could not create man page output folder.");
|
|
|
|
let man = clap_mangen::Man::new(cli);
|
|
let mut buffer: Vec<u8> = Default::default();
|
|
man.render(&mut buffer)?;
|
|
|
|
std::fs::write(man_dir.join("peshming.1"), buffer)?;
|
|
}
|
|
|
|
Ok(())
|
|
}
|