MCPcopy Create free account
hub / github.com/Chat2AnyLLM/code-agent-manager / completionCommand

Method completionCommand

internal/cli/completion.go:10–42  ·  view source on GitHub ↗
(root *cobra.Command)

Source from the content-addressed store, hash-verified

8)
9
10func (a *App) completionCommand(root *cobra.Command) *cobra.Command {
11 cmd := &cobra.Command{
12 Use: "completion [bash|zsh|fish|powershell|pwsh]",
13 Aliases: []string{"comp", "c"},
14 Short: "Generate shell completion scripts",
15 Long: "Generate shell completion scripts using Cobra's native generator. " +
16 "Source the output for the matching shell to enable command, flag, and value completions.",
17 Args: cobra.ExactArgs(1),
18 RunE: func(cmd *cobra.Command, args []string) error {
19 shell := strings.ToLower(args[0])
20 normalized := normalizeShell(shell)
21 if normalized == "" {
22 return fmt.Errorf("Unsupported shell: %s", shell)
23 }
24 out := cmd.OutOrStdout()
25 if _, err := fmt.Fprintf(out, "# code-agent-manager %s completion\n", normalized); err != nil {
26 return err
27 }
28 switch normalized {
29 case "bash":
30 return root.GenBashCompletionV2(out, true)
31 case "zsh":
32 return root.GenZshCompletion(out)
33 case "fish":
34 return root.GenFishCompletion(out, true)
35 case "powershell":
36 return root.GenPowerShellCompletionWithDesc(out)
37 }
38 return fmt.Errorf("Unsupported shell: %s", shell)
39 },
40 }
41 return cmd
42}
43
44func normalizeShell(shell string) string {
45 switch shell {

Callers 1

rootCommandMethod · 0.95

Calls 1

normalizeShellFunction · 0.85

Tested by

no test coverage detected