-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.rs
30 lines (25 loc) · 828 Bytes
/
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
use std::{env, io::Error};
use clap::CommandFactory;
use clap_complete::{generate_to, Shell};
include!("src/cli.rs");
fn main() -> Result<(), Error> {
println!("cargo::rerun-if-changed=src/cli.rs");
let outdir = match env::var_os("OUT_DIR") {
None => return Ok(()),
Some(outdir) => outdir,
};
let mut cmd = Options::command();
// New directory for completions in target/<profile>/completions
let completion_path = PathBuf::from(outdir.clone())
.ancestors()
.nth(3)
.unwrap()
.join("completions")
.into_os_string();
// Make sure the completion directory exists
std::fs::create_dir_all(&completion_path)?;
for &shell in Shell::value_variants() {
generate_to(shell, &mut cmd, "sshping", &completion_path)?;
}
Ok(())
}