-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.rs
49 lines (40 loc) · 1.21 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
#[path = "src/bin/cnc/cli.rs"]
mod cnc;
#[allow(dead_code)]
#[path = "src/bin/conceal/cli.rs"]
mod conceal;
use std::env;
use std::fs;
use std::io;
use std::path::PathBuf;
use cfg_aliases::cfg_aliases;
use clap::{Command, CommandFactory};
use clap_complete::generate_to;
use clap_complete::Shell::{Bash, Fish, PowerShell, Zsh};
use clap_complete_nushell::Nushell;
fn main() -> io::Result<()> {
cfg_aliases! {
freedesktop: {
all(
unix,
not(target_os = "macos"),
not(target_os = "ios"),
not(target_os = "android")
)}
}
if env::var_os("CONCEAL_GEN_COMPLETIONS").is_some_and(|s| s == "true") {
generate_completions(&mut cnc::Cli::command(), "cnc")?;
generate_completions(&mut conceal::Cli::command(), "conceal")?;
}
Ok(())
}
fn generate_completions(cmd: &mut Command, name: &str) -> io::Result<()> {
let dir = &PathBuf::from("completions").join(name);
fs::create_dir_all(dir)?;
generate_to(Zsh, cmd, name, dir)?;
generate_to(Bash, cmd, name, dir)?;
generate_to(Fish, cmd, name, dir)?;
generate_to(PowerShell, cmd, name, dir)?;
generate_to(Nushell, cmd, name, dir)?;
Ok(())
}