-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
41 lines (31 loc) · 991 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
31
32
33
34
35
36
37
38
39
40
41
//! Creates shell autocompletions
use std::io::Error;
#[cfg(feature = "cmd")]
use std::{env, fs, path::Path};
#[cfg(feature = "cmd")]
use clap::{CommandFactory, ValueEnum};
#[cfg(feature = "cmd")]
use clap_complete::{generate_to, shells};
#[cfg(feature = "cmd")]
mod fix_super {
//! import `cmd_arguments` to be able to generate autocommpletions from
include!("src/config/cmd_arguments.rs");
}
#[cfg(feature = "cmd")]
use fix_super::CMDArguments;
fn main() -> Result<(), Error> {
#[cfg(feature = "cmd")]
{
let outdir = Path::new("./completions");
let pkg_name = env!("CARGO_PKG_NAME");
if !outdir.exists() {
fs::create_dir_all(outdir)?;
}
let mut cmd = CMDArguments::command();
for shell in shells::Shell::value_variants() {
let path = generate_to(*shell, &mut cmd, pkg_name, outdir)?;
println!("cargo:warning=Completion file is generated: {path:?}");
}
}
Ok(())
}