feat: add build time completion generation
This commit is contained in:
28
build.rs
Normal file
28
build.rs
Normal file
@@ -0,0 +1,28 @@
|
||||
#[allow(dead_code)]
|
||||
#[path = "src/model.rs"]
|
||||
mod model;
|
||||
|
||||
include!("src/cli.rs");
|
||||
|
||||
use clap::{CommandFactory, ValueEnum};
|
||||
use clap_complete::{generate_to, Shell};
|
||||
use std::{env, io::Error};
|
||||
|
||||
fn main() -> Result<(), Error> {
|
||||
let outdir = env::var_os("SHELL_COMPLETIONS_DIR")
|
||||
.or_else(|| env::var_os("OUT_DIR"));
|
||||
|
||||
let Some(outdir) = outdir else {
|
||||
return Ok(());
|
||||
};
|
||||
|
||||
let mut cmd = Cli::command();
|
||||
|
||||
for shell in Shell::value_variants() {
|
||||
let path = generate_to(*shell, &mut cmd, "todo", &outdir)?;
|
||||
|
||||
println!("cargo:warning=completion file is generated: {path:?}");
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user