-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.rs
63 lines (55 loc) · 2.17 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
56
57
58
59
60
61
62
63
use clap::IntoApp;
use clap_complete::{generate_to, shells};
use std::env;
use std::io::Error;
use std::path::Path;
include!("src/app.rs");
const APP_NAME: &'static str = "gmux";
fn main() -> Result<(), Error> {
// HACK: It's very much a hack to expose completion files as artifacts.
// `cargo` does not support installing completions yet, but package
// managers could, so it's desirable to generate them.
// When the `--out-dir` flag goes out of its experimental state,
// this won't be needed anymore as packagers will be able to specify
// the output directory and access the completion files directly.
// Or we could use nightly right now and forget about all this.
let manifest_dir = match env::var_os("CARGO_MANIFEST_DIR") {
None => {
println!("cargo:warning=Could not find manifest dir, aborting completions generation.");
return Ok(());
}
Some(manifest_dir) => manifest_dir,
};
let profile = match env::var_os("PROFILE") {
None => {
println!("cargo:warning=Could not find profile, aborting completions generation.");
return Ok(());
}
Some(profile) => profile,
};
let target_dir = Path::new(&manifest_dir).join("target").join(profile);
let mut app = Application::into_app();
let path = generate_to(shells::Bash, &mut app, APP_NAME, &target_dir)?;
println!(
"cargo:warning=bash completion file is generated: {:?}",
path
);
let path = generate_to(shells::Zsh, &mut app, APP_NAME, &target_dir)?;
println!("cargo:warning=zsh completion file is generated: {:?}", path);
let path = generate_to(shells::Fish, &mut app, APP_NAME, &target_dir)?;
println!(
"cargo:warning=fish completion file is generated: {:?}",
path
);
let path = generate_to(shells::PowerShell, &mut app, APP_NAME, &target_dir)?;
println!(
"cargo:warning=powershell completion file is generated: {:?}",
path
);
let path = generate_to(shells::Elvish, &mut app, APP_NAME, &target_dir)?;
println!(
"cargo:warning=elvish completion file is generated: {:?}",
path
);
Ok(())
}