use clap::CommandFactory;
use clap_complete::{aot::Shell, generate_to};
use std::env;
use std::ffi::OsString;
use std::io::Error;
include!("src/cli.rs");
fn main() -> Result<(), Error> {
let outdir = match env::var_os("OUT_DIR") {
None => return Ok(()),
Some(outdir) => outdir,
};
create_file(Shell::Bash, &outdir)?;
create_file(Shell::Zsh, &outdir)?;
Ok(())
}
fn create_file(shell: clap_complete::aot::Shell, outdir: &OsString) -> Result<(), Error> {
let mut cmd = Cli::command();
let path = generate_to(
shell, &mut cmd, "flyboat", outdir, )?;
let file_name = path.file_name().unwrap();
let mut result_path = path.clone();
while result_path.pop() {
if let Some(name) = result_path.file_name()
&& name == "build"
{
result_path.pop();
result_path.push(file_name);
break;
}
}
std::fs::copy(path, &result_path)?;
Ok(())
}