2022-07-15 21:55:31 +00:00
|
|
|
// 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 <https://www.gnu.org/licenses/>.
|
|
|
|
|
2022-07-15 23:01:48 +00:00
|
|
|
use std::{
|
|
|
|
fs,
|
|
|
|
io::{self, Error},
|
|
|
|
path::PathBuf,
|
|
|
|
};
|
2022-07-15 21:34:09 +00:00
|
|
|
|
|
|
|
use clap_complete::{generate_to, shells, Generator};
|
2020-07-22 16:47:26 +00:00
|
|
|
|
|
|
|
include!("src/cli.rs");
|
|
|
|
|
2022-07-16 00:34:51 +00:00
|
|
|
const OUTDIR: &str = "target/completions";
|
2022-07-15 23:01:48 +00:00
|
|
|
|
2022-07-15 21:34:09 +00:00
|
|
|
fn main() -> Result<(), Error> {
|
|
|
|
let mut cmd = build_cli();
|
|
|
|
|
2022-07-15 23:01:48 +00:00
|
|
|
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:?}");
|
2022-07-15 21:34:09 +00:00
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2022-07-15 23:01:48 +00:00
|
|
|
fn generate_completions<G: Generator>(shell: G, cmd: &mut clap::Command) -> Result<PathBuf, Error> {
|
|
|
|
generate_to(shell, cmd, env!("CARGO_PKG_NAME"), OUTDIR)
|
2020-07-22 16:47:26 +00:00
|
|
|
}
|