-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
build.rs
55 lines (43 loc) · 1.38 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
44
45
46
47
48
49
50
51
52
53
54
55
include!("src/config/cli.rs");
use clap::Command as ClapCommand;
use clap::CommandFactory;
use clap_complete::generate_to;
use clap_complete::Shell::{Bash, Fish, Zsh};
use clap_mangen::Man;
use std::error::Error;
use std::fs;
use vergen_gitcl::Emitter;
use vergen_gitcl::GitclBuilder;
static NAME: &str = "rmpc";
fn generate_man_pages(cmd: ClapCommand) -> Result<(), Box<dyn Error>> {
let out = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("target").join("man");
let mut buffer = Vec::default();
Man::new(cmd).render(&mut buffer)?;
fs::create_dir_all(&out)?;
fs::write(out.join(NAME.to_owned() + ".1"), buffer)?;
Ok(())
}
fn generate_shell_completions(mut cmd: ClapCommand) -> Result<(), Box<dyn Error>> {
let out = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("target")
.join("completions");
std::fs::create_dir_all(&out)?;
for shell in [Bash, Fish, Zsh] {
generate_to(shell, &mut cmd, NAME, &out)?;
}
Ok(())
}
fn emit_git_info() -> Result<(), Box<dyn Error>> {
Emitter::default()
.add_instructions(&GitclBuilder::default().describe(false, false, None).build()?)?
.emit()?;
Ok(())
}
fn main() -> Result<(), Box<dyn Error>> {
let mut cmd = Args::command();
cmd.set_bin_name(NAME);
generate_man_pages(cmd.clone())?;
generate_shell_completions(cmd)?;
emit_git_info()?;
Ok(())
}