-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rs
37 lines (31 loc) · 948 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
use clap::IntoApp;
use clap_complete::{generate_to, shells};
use std::env;
use std::io::Error;
#[allow(dead_code)]
#[path = "src/args.rs"]
mod args;
fn main() -> Result<(), Error> {
let outdir = match env::var_os("OUT_DIR") {
None => return Ok(()),
Some(outdir) => outdir,
};
let mut app = args::Args::command();
macro_rules! gen {
($shell:expr) => {{
let path = generate_to(
$shell,
&mut app, // We need to specify what generator to use
clap::crate_name!(), // We need to specify the bin name manually
&outdir, // We need to specify where to write to
)?;
println!("cargo:warning=completion file generated: {:?}", path);
}};
}
gen!(shells::Bash);
gen!(shells::Elvish);
gen!(shells::Fish);
gen!(shells::PowerShell);
gen!(shells::Zsh);
Ok(())
}