use clap_complete::{generate, Shell as ClapShell};
use crate::commands::Shell;
use std::io;
use std::env;
pub fn generate_completions(shell: Shell, app: &mut clap::Command) {
let clap_shell = match shell {
Shell::Bash => ClapShell::Bash,
Shell::Zsh => ClapShell::Zsh,
Shell::Fish => ClapShell::Fish,
Shell::PowerShell => ClapShell::PowerShell,
};
let binary_name = env::args()
.next()
.and_then(|path| {
std::path::Path::new(&path)
.file_name()
.and_then(|name| name.to_str())
.map(|s| {
s.strip_suffix(".exe").unwrap_or(s).to_string()
})
})
.unwrap_or_else(|| "cargo-script".to_string());
generate(clap_shell, app, &binary_name, &mut io::stdout());
}