-
Notifications
You must be signed in to change notification settings - Fork 251
/
completions.go
38 lines (32 loc) · 1.06 KB
/
completions.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Package completions implements command completion support.
package completions
import (
"github.com/spf13/cobra"
"github.com/taskcluster/taskcluster/v28/clients/client-shell/cmds/root"
)
var (
defaultFilename = "bash_completion.sh"
)
func init() {
// Add the task subtree to the root.
use := "completions <filename (default:" + defaultFilename + ")>"
completionsCommand := &cobra.Command{
Short: "Provides bash completion script.",
Long: `Writes a bash completion script to the path specified, or the default filename if not given.
To use, do one of the following:
'source bash_completion.sh' to add to your current shell,
Add 'source bash_completion.sh' to your bash login scripts
On Linux you can also copy it to /etc/bash_completion.d/ so that future bash shells have it active.
`,
RunE: genCompletion,
Use: use,
}
root.Command.AddCommand(completionsCommand)
}
func genCompletion(cmd *cobra.Command, args []string) error {
filename := defaultFilename
if len(args) != 0 {
filename = args[0]
}
return root.Command.GenBashCompletionFile(filename)
}