use anyhow::Result; use clap::CommandFactory; use clap_complete::{generate_to, Shell}; use std::path::PathBuf; use crate::cli::Cli; pub fn ejecutar(shell: &str) -> Result<()> { let shell = match shell { "bash" => Shell::Bash, "zsh" => Shell::Zsh, "fish" => Shell::Fish, _ => anyhow::bail!("Shell no soportada: {}", shell), }; let mut cmd = Cli::command(); let bin_name = "crustaceo-tools"; let out_dir = PathBuf::from("."); let archivo = match shell { Shell::Bash => "crustaceo-tools.bash", Shell::Zsh => "_crustaceo-tools", Shell::Fish => "crustaceo-tools.fish", _ => unreachable!(), }; let path = generate_to(shell, &mut cmd, bin_name, &out_dir)?; println!("Autocompletado generado: {}", path.display()); println!(); println!("Instalalo segun tu shell:"); println!(); match shell { Shell::Bash => { println!(" source {}", archivo); println!(" # O anadelo a ~/.bashrc:"); println!(" echo 'source $(pwd)/{}' >> ~/.bashrc", archivo); } Shell::Zsh => { println!(" # Copia a un directorio en tu fpath:"); println!(" cp {} ~/.zsh/completions/", archivo); println!(" # O directamente:"); println!(" source {}", archivo); } Shell::Fish => { println!(" mkdir -p ~/.config/fish/completions/"); println!(" cp {} ~/.config/fish/completions/", archivo); } _ => unreachable!(), } Ok(()) }