MCPcopy Index your code
hub / github.com/coder/coder / completion

Method completion

cli/completion.go:13–71  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

11)
12
13func (*RootCmd) completion() *serpent.Command {
14 var shellName string
15 var printOutput bool
16 shellOptions := completion.ShellOptions(&shellName)
17 return &serpent.Command{
18 Use: "completion",
19 Short: "Install or update shell completion scripts for the detected or chosen shell.",
20 Options: []serpent.Option{
21 {
22 Flag: "shell",
23 FlagShorthand: "s",
24 Description: "The shell to install completion for.",
25 Value: shellOptions,
26 },
27 {
28 Flag: "print",
29 Description: "Print the completion script instead of installing it.",
30 FlagShorthand: "p",
31
32 Value: serpent.BoolOf(&printOutput),
33 },
34 },
35 Handler: func(inv *serpent.Invocation) error {
36 if shellName != "" {
37 shell, err := completion.ShellByName(shellName, inv.Command.Parent.Name())
38 if err != nil {
39 return err
40 }
41 if printOutput {
42 return shell.WriteCompletion(inv.Stdout)
43 }
44 return installCompletion(inv, shell)
45 }
46 shell, err := completion.DetectUserShell(inv.Command.Parent.Name())
47 if err == nil {
48 return installCompletion(inv, shell)
49 }
50 if !isTTYOut(inv) {
51 return xerrors.New("could not detect the current shell, please specify one with --shell or run interactively")
52 }
53 // Silently continue to the shell selection if detecting failed in interactive mode
54 choice, err := cliui.Select(inv, cliui.SelectOptions{
55 Message: "Select a shell to install completion for:",
56 Options: shellOptions.Choices,
57 })
58 if err != nil {
59 return err
60 }
61 shellChoice, err := completion.ShellByName(choice, inv.Command.Parent.Name())
62 if err != nil {
63 return err
64 }
65 if printOutput {
66 return shellChoice.WriteCompletion(inv.Stdout)
67 }
68 return installCompletion(inv, shellChoice)
69 },
70 }

Callers 1

CoreSubcommandsMethod · 0.95

Calls 5

SelectFunction · 0.92
installCompletionFunction · 0.85
isTTYOutFunction · 0.85
NameMethod · 0.65
NewMethod · 0.65

Tested by

no test coverage detected