forked from ClementTsang/bottom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rs
55 lines (46 loc) · 1.65 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
use clap_complete::{generate_to, shells::Shell};
use std::{
env, fs,
io::Result,
path::{Path, PathBuf},
};
include!("src/clap.rs");
fn create_dir(dir: &Path) -> Result<()> {
let res = fs::create_dir_all(&dir);
match &res {
Ok(()) => {}
Err(err) => {
eprintln!(
"Failed to create a directory at location {:?}, encountered error {:?}. Aborting...",
dir, err
);
}
}
res
}
fn main() -> Result<()> {
if env::var_os("GENERATE").is_some() {
// OUT_DIR is where extra build files are written to for Cargo.
let completion_out_dir = PathBuf::from("completion");
let manpage_out_dir = PathBuf::from("manpage");
create_dir(&completion_out_dir)?;
create_dir(&manpage_out_dir)?;
// Generate completions
let mut app = build_app();
generate_to(Shell::Bash, &mut app, "btm", &completion_out_dir)?;
generate_to(Shell::Zsh, &mut app, "btm", &completion_out_dir)?;
generate_to(Shell::Fish, &mut app, "btm", &completion_out_dir)?;
generate_to(Shell::PowerShell, &mut app, "btm", &completion_out_dir)?;
generate_to(Shell::Elvish, &mut app, "btm", &completion_out_dir)?;
// Generate manpage
let app = app.name("btm");
let man = clap_mangen::Man::new(app);
let mut buffer: Vec<u8> = Default::default();
man.render(&mut buffer)?;
std::fs::write(manpage_out_dir.join("btm.1"), buffer)?;
}
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed=./src/clap.rs");
println!("cargo:rerun-if-env-changed=GENERATE");
Ok(())
}