// This file is part of the "lamp" program.
// Copyright (C) 2022 crapStone
// You should have received a copy of the GNU General Public License
// along with this program. If not, see .
use std::{
fs,
io::{self, Error},
path::PathBuf,
};
use clap_complete::{generate_to, shells, Generator};
include!("src/cli.rs");
const OUTDIR: &str = "completions";
fn main() -> Result<(), Error> {
let mut cmd = build_cli();
if let Err(why) = fs::create_dir(OUTDIR) {
if why.kind() != io::ErrorKind::AlreadyExists {
eprintln!("cargo:error=could not create directory: {OUTDIR}");
return Err(why);
}
}
let path = generate_completions(shells::Bash, &mut cmd)?;
println!("cargo:debug=completion file is generated: {path:?}");
let path = generate_completions(shells::Zsh, &mut cmd)?;
println!("cargo:debug=completion file is generated: {path:?}");
let path = generate_completions(shells::Fish, &mut cmd)?;
println!("cargo:debug=completion file is generated: {path:?}");
Ok(())
}
fn generate_completions(shell: G, cmd: &mut clap::Command) -> Result {
generate_to(shell, cmd, env!("CARGO_PKG_NAME"), OUTDIR)
}