-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rs
52 lines (43 loc) · 1.31 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
// SPDX-FileCopyrightText: 2023 Aurélien Gâteau <[email protected]>
//
// SPDX-License-Identifier: GPL-3.0-or-later
use clap::CommandFactory;
use clap_complete::generate_to;
use clap_complete::shells::{Bash, Elvish, Fish, PowerShell, Zsh};
use std::env;
use std::io::Error;
use std::path::PathBuf;
include!("./src/cli.rs");
/// Generates the shell auto-completion files in the `completions` dir
fn main() -> Result<(), Error> {
println!("cargo:rerun-if-changed=src/cli.rs");
let directory = match env::var("CARGO_MANIFEST_DIR").as_ref() {
Ok(x) => PathBuf::from(x).join("completions"),
Err(_) => {
return Ok(());
}
};
let command = &mut Cli::command();
let name = &command.get_name().to_string();
println!(
"cargo:info=Generated {:?}",
generate_to(Bash, command, name, &directory)?
);
println!(
"cargo:info=Generated {:?}",
generate_to(Elvish, command, name, &directory)?
);
println!(
"cargo:info=Generated {:?}",
generate_to(Fish, command, name, &directory)?
);
println!(
"cargo:info=Generated {:?}",
generate_to(PowerShell, command, name, &directory)?
);
println!(
"cargo:info=Generated {:?}",
generate_to(Zsh, command, name, &directory)?
);
Ok(())
}