flyboat 2.0.0

Container environment manager for development
Documentation
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,  // We need to specify what generator to use
        "flyboat", // We need to specify the bin name manually
        outdir,    // We need to specify where to write to
    )?;

    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)?;
    // println!("cargo:warning=completion file is generated: {result_path:?}");
    // println!("cargo:warning=Copy to `/usr/share/bash-completion/completions/flyboat`");
    // println!(
    //     "cargo:warning=`sudo cp {result_path:?} \"/usr/share/bash-completion/completions/flyboat\"`"
    // );

    Ok(())
}