alibaba/open-code-review · error

unsupported shell: %s

Error message

unsupported shell: %s

What it means

The `ocr completion` command generates shell completion scripts for a fixed set of shells (bash, zsh, fish, powershell via cobra generators). Any other first argument reaches the default branch and produces this error. There is no fuzzy matching and no case normalization.

Source

Thrown at cmd/opencodereview/completion.go:30

var completionCmd = &cobra.Command{
	Use:       "completion [bash|zsh|fish|powershell]",
	Short:     "Generate shell completion scripts",
	Long:      completionLongHelp,
	ValidArgs: []string{"bash", "zsh", "fish", "powershell"},
	Args:      cobra.MatchAll(exactArgs(1), cobra.OnlyValidArgs),
	RunE: func(cmd *cobra.Command, args []string) error {
		switch args[0] {
		case "bash":
			return rootCmd.GenBashCompletionV2(os.Stdout, true)
		case "zsh":
			return rootCmd.GenZshCompletion(os.Stdout)
		case "fish":
			return rootCmd.GenFishCompletion(os.Stdout, true)
		case "powershell":
			return rootCmd.GenPowerShellCompletionWithDesc(os.Stdout)
		default:
			return fmt.Errorf("unsupported shell: %s", args[0])
		}
	},
}

const completionLongHelp = `Generate shell completion scripts for OCR.

To load completions:

Bash:
  $ source <(ocr completion bash)
  # To load completions for each session, execute once:
  # Linux:
  $ ocr completion bash > /etc/bash_completion.d/ocr
  # macOS:
  $ ocr completion bash > $(brew --prefix)/etc/bash_completion.d/ocr

Zsh:
  # If shell completion is not already enabled in your environment,

View on GitHub (pinned to 5cf97d0d15)

Solutions

  1. Use an exact supported name, lowercase: `ocr completion bash|zsh|fish|powershell`.
  2. For PowerShell Core, `powershell` output also works: `ocr completion powershell > _ocr.ps1`.
  3. For unsupported shells (e.g. sh/dash), fall back to bash completion or rely on cobra's __complete hidden command.
  4. Check the command's long help (`ocr completion --help`) for the supported list.

Example fix

// before
ocr completion Bash >> ~/.bashrc
// after
ocr completion bash >> ~/.bashrc
Defensive patterns

Strategy: validation

Validate before calling

// shell: verify the shell argument before invoking ocr completion
case "$shell" in
  bash|zsh|fish|powershell) ocr completion "$shell" ;;
  pwsh) ocr completion powershell ;;
  *) echo "unsupported shell: $shell"; exit 1 ;;
esac

Try / catch

out, err := exec.Command("ocr", "completion", shell).CombinedOutput()
if err != nil && strings.Contains(string(out), "unsupported shell") {
	return fmt.Errorf("completion only supports bash, zsh, fish, powershell")
}

Prevention

When it happens

Trigger: Running `ocr completion <arg>` where arg is not one of the supported shell names — e.g. `ocr completion Bash`, `ocr completion sh`, `ocr completion pwsh`, `ocr completion powershell.exe`.

Common situations: Following install docs written for another tool; using `pwsh` (PowerShell Core) expecting it to be recognized separately; capitalizing the shell name in a setup script; passing `zsh` to a tool that only lists it with different casing in docs.

Related errors


AI-assisted analysis of alibaba/open-code-review@5cf97d0d15 (2026-09-02). Data as JSON: /api/errors/0fb0918bc8d2f84c. Report an issue: GitHub.