forked from zaquestion/lab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompletion.go
31 lines (26 loc) · 985 Bytes
/
completion.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
package cmd
import (
"fmt"
"github.com/rsteube/carapace"
"github.com/spf13/cobra"
)
// completionCmd represents the completion command
var completionCmd = &cobra.Command{
Use: "completion",
Short: "Generates the shell autocompletion [bash, elvish, fish, powershell, zsh]",
Long: `Generates the shell autocompletion [bash, elvish, fish, powershell, zsh]
Most scripts can be direcly sourced (though using pre-generated versions is recommended):
bash : source <(lab completion bash)
elvish : lab completion elvish > lab.elv; -source lab.elv
fish : lab completion fish | source
powershell : lab completion powershell | Out-String | Invoke-Expression
zsh : source <(lab completion zsh)`,
Args: cobra.ExactArgs(1),
ValidArgs: []string{"bash", "elvish", "fish", "powershell", "zsh"},
Run: func(cmd *cobra.Command, args []string) {
fmt.Println(carapace.Gen(cmd).Snippet(args[0]))
},
}
func init() {
RootCmd.AddCommand(completionCmd)
}