diff --git a/src/cortex-cli/src/cli/args.rs b/src/cortex-cli/src/cli/args.rs index 641d63a4a..02442aedd 100644 --- a/src/cortex-cli/src/cli/args.rs +++ b/src/cortex-cli/src/cli/args.rs @@ -551,7 +551,7 @@ pub struct LogoutCommand { #[derive(Args)] pub struct CompletionCommand { /// Shell to generate completions for. - #[arg(value_enum)] + #[arg(value_parser = parse_completion_shell, value_name = "SHELL")] pub shell: Option, /// Install completions to your shell configuration file. @@ -559,6 +559,19 @@ pub struct CompletionCommand { pub install: bool, } +fn parse_completion_shell(shell: &str) -> Result { + match shell.to_lowercase().as_str() { + "bash" => Ok(clap_complete::Shell::Bash), + "zsh" => Ok(clap_complete::Shell::Zsh), + "fish" => Ok(clap_complete::Shell::Fish), + "powershell" | "pwsh" => Ok(clap_complete::Shell::PowerShell), + "elvish" => Ok(clap_complete::Shell::Elvish), + _ => Err(format!( + "invalid shell '{shell}'. Expected one of: bash, zsh, fish, powershell, pwsh, elvish" + )), + } +} + /// Init command - initialize AGENTS.md. #[derive(Args)] pub struct InitCommand { @@ -1754,6 +1767,27 @@ mod tests { } } + #[test] + fn test_completion_command_pwsh_alias() { + let cli = Cli::try_parse_from(["cortex", "completion", "pwsh"]) + .expect("should parse completion pwsh"); + if let Some(Commands::Completion(completion)) = cli.command { + assert_eq!(completion.shell, Some(clap_complete::Shell::PowerShell)); + } else { + panic!("Expected Completion command"); + } + } + + #[test] + fn test_completion_command_rejects_unknown_shell() { + let err = Cli::try_parse_from(["cortex", "completion", "tcsh"]) + .expect_err("should reject unsupported completion shell"); + assert!( + err.to_string().contains("Expected one of"), + "unexpected error: {err}" + ); + } + #[test] fn test_completion_command_install() { let cli = Cli::try_parse_from(["cortex", "completion", "--install"])