Skip to content

Commit bca7f89

Browse files
committed
fix: accept pwsh completion alias
1 parent 940e83c commit bca7f89

1 file changed

Lines changed: 36 additions & 1 deletion

File tree

src/cortex-cli/src/cli/args.rs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,14 +551,27 @@ pub struct LogoutCommand {
551551
#[derive(Args)]
552552
pub struct CompletionCommand {
553553
/// Shell to generate completions for.
554-
#[arg(value_enum)]
554+
#[arg(value_parser = parse_completion_shell)]
555555
pub shell: Option<clap_complete::Shell>,
556556

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

562+
fn parse_completion_shell(value: &str) -> Result<clap_complete::Shell, String> {
563+
match value.to_ascii_lowercase().as_str() {
564+
"bash" => Ok(clap_complete::Shell::Bash),
565+
"elvish" => Ok(clap_complete::Shell::Elvish),
566+
"fish" => Ok(clap_complete::Shell::Fish),
567+
"powershell" | "pwsh" => Ok(clap_complete::Shell::PowerShell),
568+
"zsh" => Ok(clap_complete::Shell::Zsh),
569+
_ => Err(format!(
570+
"invalid shell '{value}'. Expected one of: bash, elvish, fish, powershell, pwsh, zsh"
571+
)),
572+
}
573+
}
574+
562575
/// Init command - initialize AGENTS.md.
563576
#[derive(Args)]
564577
pub struct InitCommand {
@@ -1754,6 +1767,28 @@ mod tests {
17541767
}
17551768
}
17561769

1770+
#[test]
1771+
fn test_completion_command_powershell() {
1772+
let cli = Cli::try_parse_from(["cortex", "completion", "powershell"])
1773+
.expect("should parse completion powershell");
1774+
if let Some(Commands::Completion(completion)) = cli.command {
1775+
assert_eq!(completion.shell, Some(clap_complete::Shell::PowerShell));
1776+
} else {
1777+
panic!("Expected Completion command");
1778+
}
1779+
}
1780+
1781+
#[test]
1782+
fn test_completion_command_pwsh_alias() {
1783+
let cli = Cli::try_parse_from(["cortex", "completion", "pwsh"])
1784+
.expect("should parse completion pwsh");
1785+
if let Some(Commands::Completion(completion)) = cli.command {
1786+
assert_eq!(completion.shell, Some(clap_complete::Shell::PowerShell));
1787+
} else {
1788+
panic!("Expected Completion command");
1789+
}
1790+
}
1791+
17571792
#[test]
17581793
fn test_completion_command_install() {
17591794
let cli = Cli::try_parse_from(["cortex", "completion", "--install"])

0 commit comments

Comments
 (0)