Skip to content

[BUG] cortex completion pwsh is rejected even though Cortex internally treats pwsh as PowerShell #53188

Description

@chris-dev77777

Project

cortex

Description

The explicit completion command uses clap_complete::Shell, which only accepts powershell, while Cortex’s own shell-detection helpers already recognize both powershell and pwsh as the same shell. This makes the CLI reject a shell name that the rest of Cortex already treats as valid.

Error Message

Debug Logs

System Information

OS: Windows 10
RAM: 16 GB
CPU: Intel(R) Core(TM) i7-1165G7 @ 2.8GHz(8 CPUs), ~2.8GH

Screenshots

https://github.com/chris-dev777/image/blob/main/40.mp4

Steps to Reproduce

Run cortex completion pwsh.
Observe the argument parsing result.

Expected Behavior

pwsh should be accepted as an alias for PowerShell, consistent with Cortex’s internal shell detection.

Actual Behavior

The command rejects pwsh, even though other Cortex code paths map pwsh to PowerShell.

Additional Context

Explicit cortex completion (clap only knows clap_complete::Shell variants)
src/cortex-cli/src/cli/args.rs — CompletionCommand: optional positional shell is #[arg(value_enum)] pub shell: Option<clap_complete::Shell> (around lines 550–555). Clap’s value_enum for clap_complete::Shell only allows that crate’s variant names (e.g. powershell), not pwsh, so cortex completion pwsh fails parsing.
Handler (uses whatever Shell was parsed + env default)
src/cortex-cli/src/cli/handlers.rs
handle_completion (around lines 246–252): completion_cli.shell.unwrap_or_else(detect_shell_from_env) then generate_completions / install_completions.
detect_shell_from_env (around lines 298–331): maps file_name of $SHELL with "powershell" | "pwsh" => Shell::PowerShell — both resolve to clap_complete::Shell::PowerShell without going through clap’s string parser.
generate_completions (around lines 333–359): generate(shell, &mut cmd, "cortex", &mut buffer) from clap_complete.
Other Cortex “shell name” helpers (same idea as detect_shell_from_env)
src/cortex-cli/src/completion_setup.rs — detect_shell() (around lines 55–70): "powershell" | "pwsh" => Some(Shell::PowerShell) using clap_complete::Shell.
src/cortex-engine/src/shell.rs (ShellType::from_name) and src/cortex-shell-snapshot/src/shell_type.rs — broader recognition of PowerShell names for the engine/snapshot layer (not the completion subcommand parser).
Dispatch
src/cortex-cli/src/cli/handlers.rs — Some(Commands::Completion(completion_cli)) => handle_completion(completion_cli) (around line 40).
Summary: The strict surface is CompletionCommand.shell: Option<clap_complete::Shell> in args.rs (clap value_enum). The lenient path is detect_shell_from_env (and completion_setup::detect_shell) in handlers.rs / completion_setup.rs, which treat pwsh as Shell::PowerShell without exposing pwsh as a valid completion subcommand token.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingideIssues related to IDEvalidValid issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions