in main.go [603:627]
func completionRun(cmd *cobra.Command, args []string) error {
switch shell := args[0]; shell {
case "bash":
if err := rootCmd.GenBashCompletion(stdout); err != nil {
err = fmt.Errorf("failed to generate bash completion: %w", err)
return apiError(err)
}
case "zsh":
if err := rootCmd.GenZshCompletion(stdout); err != nil {
err = fmt.Errorf("failed to generate zsh completion: %w", err)
return apiError(err)
}
// enable the `source <(berglas completion SHELL)` pattern for zsh
if _, err := io.WriteString(stdout, "compdef _berglas berglas\n"); err != nil {
err = fmt.Errorf("failed to run compdef: %w", err)
return apiError(err)
}
default:
err := fmt.Errorf("unknown completion %q", shell)
return misuseError(err)
}
return nil
}