/** * Completion Command * Generate shell completion scripts for bash/zsh */ import { COMMANDS } from '@celilo/core'; import { generateBashCompletion, generateFishCompletion } from '../completion'; import { generateRichZshCompletion } from '../generate-zsh-completion'; import { celiloIntro } from '../prompts'; import type { CommandResult } from '../types'; /** * Handle completion command * * @param args - Command arguments: [shell] * @param flags - Command flags */ export async function handleCompletion( args: string[], _flags: Record = {}, ): Promise { try { const shell = args[0]; if (!shell) { celiloIntro('Shell Completion'); return { success: false, error: `Shell argument required. Usage: celilo completion bash Generate bash completion script celilo completion zsh Generate zsh completion script celilo completion fish Generate fish completion script Install zsh completions: celilo completion zsh > ~/.zsh/completions/_celilo exec zsh `, }; } if (shell === 'bash') { return { success: true, message: generateBashCompletion() }; } if (shell === 'zsh') { return { success: true, message: generateRichZshCompletion(COMMANDS) }; } if (shell === 'fish') { return { success: true, message: generateFishCompletion() }; } celiloIntro('Shell Completion'); return { success: false, error: `Unknown shell: ${shell} Supported shells: bash Generate bash completion script zsh Generate zsh completion script fish Generate fish completion script Usage: # Bash celilo completion bash > /etc/bash_completion.d/celilo # OR for user install: celilo completion bash >> ~/.bashrc # Zsh celilo completion zsh > ~/.zsh/completions/_celilo # OR for user install: celilo completion zsh > /usr/local/share/zsh/site-functions/_celilo # Fish celilo completion fish > ~/.config/fish/completions/celilo.fish `, }; } catch (error) { return { success: false, error: `Failed to generate completion script: ${error instanceof Error ? error.message : String(error)}`, }; } }