Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/dev/gpctl/cmd/completion.go
2498 views
1
// Copyright (c) 2020 Gitpod GmbH. All rights reserved.
2
// Licensed under the GNU Affero General Public License (AGPL).
3
// See License.AGPL.txt in the project root for license information.
4
5
package cmd
6
7
import (
8
"os"
9
10
"github.com/spf13/cobra"
11
)
12
13
var completionCmd = &cobra.Command{
14
Use: "completion [bash|zsh|fish|powershell]",
15
Short: "Generate completion script",
16
Long: `To load completions:
17
18
Bash:
19
20
$ source <(gpctl completion bash)
21
22
# To load completions for each session, execute once:
23
# Linux:
24
$ gpctl completion bash > /etc/bash_completion.d/gpctl
25
# macOS:
26
$ gpctl completion bash > /usr/local/etc/bash_completion.d/gpctl
27
28
Zsh:
29
30
# If shell completion is not already enabled in your environment,
31
# you will need to enable it. You can execute the following once:
32
33
$ echo "autoload -U compinit; compinit" >> ~/.zshrc
34
35
# To load completions for each session, execute once:
36
$ gpctl completion zsh > "${fpath[1]}/_gpctl"
37
38
# You will need to start a new shell for this setup to take effect.
39
40
fish:
41
42
$ gpctl completion fish | source
43
44
# To load completions for each session, execute once:
45
$ gpctl completion fish > ~/.config/fish/completions/gpctl.fish
46
47
PowerShell:
48
49
PS> gpctl completion powershell | Out-String | Invoke-Expression
50
51
# To load completions for every new session, run:
52
PS> gpctl completion powershell > gpctl.ps1
53
# and source this file from your PowerShell profile.
54
`,
55
DisableFlagsInUseLine: true,
56
ValidArgs: []string{"bash", "zsh", "fish", "powershell"},
57
Args: cobra.ExactValidArgs(1),
58
Run: func(cmd *cobra.Command, args []string) {
59
switch args[0] {
60
case "bash":
61
cmd.Root().GenBashCompletion(os.Stdout)
62
case "zsh":
63
cmd.Root().GenZshCompletion(os.Stdout)
64
case "fish":
65
cmd.Root().GenFishCompletion(os.Stdout, true)
66
case "powershell":
67
cmd.Root().GenPowerShellCompletionWithDesc(os.Stdout)
68
}
69
},
70
}
71
72
func init() {
73
rootCmd.AddCommand(completionCmd)
74
}
75
76