-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
43 lines (32 loc) · 1.13 KB
/
build.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#[path = "src/cli/mod.rs"]
mod cli;
#[path = "src/consts/mod.rs"]
mod consts;
use clap::Command;
use clap::CommandFactory;
use clap_complete::generate_to;
use clap_complete::Shell::{Bash, Fish, Zsh};
use clap_mangen::Man;
use cli::Cli;
static NAME: &str = "sakaya";
fn generate_man_pages(cmd: Command) {
let man_dir = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("target/man");
std::fs::create_dir_all(&man_dir).unwrap();
let man = Man::new(cmd);
let mut buffer: Vec<u8> = Default::default();
man.render(&mut buffer).expect("Man page generation failed");
std::fs::write(man_dir.join(NAME.to_owned() + ".1"), buffer).expect("Failed to write man page");
}
fn generate_shell_completions(mut cmd: Command) {
let comp_dir = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("target/completions");
std::fs::create_dir_all(&comp_dir).unwrap();
for shell in [Bash, Fish, Zsh] {
generate_to(shell, &mut cmd, NAME, &comp_dir).unwrap();
}
}
fn main() {
let mut cmd = Cli::command();
cmd.set_bin_name(NAME);
generate_man_pages(cmd.clone());
generate_shell_completions(cmd);
}