Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 36 additions & 1 deletion src/cortex-cli/src/cli/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -551,14 +551,27 @@ pub struct LogoutCommand {
#[derive(Args)]
pub struct CompletionCommand {
/// Shell to generate completions for.
#[arg(value_enum)]
#[arg(value_parser = parse_completion_shell)]
pub shell: Option<clap_complete::Shell>,

/// Install completions to your shell configuration file.
#[arg(long = "install")]
pub install: bool,
}

fn parse_completion_shell(value: &str) -> Result<clap_complete::Shell, String> {
match value.to_ascii_lowercase().as_str() {
"bash" => Ok(clap_complete::Shell::Bash),
"elvish" => Ok(clap_complete::Shell::Elvish),
"fish" => Ok(clap_complete::Shell::Fish),
"powershell" | "pwsh" => Ok(clap_complete::Shell::PowerShell),
"zsh" => Ok(clap_complete::Shell::Zsh),
_ => Err(format!(
"invalid shell '{value}'. Expected one of: bash, elvish, fish, powershell, pwsh, zsh"
)),
}
}

/// Init command - initialize AGENTS.md.
#[derive(Args)]
pub struct InitCommand {
Expand Down Expand Up @@ -1754,6 +1767,28 @@ mod tests {
}
}

#[test]
fn test_completion_command_powershell() {
let cli = Cli::try_parse_from(["cortex", "completion", "powershell"])
.expect("should parse completion powershell");
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_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_install() {
let cli = Cli::try_parse_from(["cortex", "completion", "--install"])
Expand Down