use crate::cli::Cli;
use miette::Result;

pub(crate) fn generate() -> Result<()> {
    // The declaration *is* the spec: the same tables that parsed the command line print it,
    // with no bridge and no second model in between. `effect` in particular is now declared
    // on each command rather than patched in here afterwards, since clap could not say it,
    // and `repository` and `source_code_link_template` used to be appended here from a
    // checked-in KDL fragment for the same reason — the derive can say both now.
    println!("// @generated by usage-cli from its own parse tables");
    println!("{}", Cli::to_kdl().trim());

    Ok(())
}

pub(crate) fn complete(shell: &str) -> Result<()> {
    match shell {
        "bash" => print!("{}", include_str!("../assets/completions/usage.bash")),
        "fish" => print!("{}", include_str!("../assets/completions/usage.fish")),
        "zsh" => print!("{}", include_str!("../assets/completions/_usage")),
        _ => {
            miette::bail!("unsupported shell: {}", shell);
        }
    };

    Ok(())
}
