File tree Expand file tree Collapse file tree 1 file changed +28
-5
lines changed
Expand file tree Collapse file tree 1 file changed +28
-5
lines changed Original file line number Diff line number Diff line change 11package main
22
33import (
4+ "fmt"
45 "os"
6+ "strings"
57
68 "github.com/spf13/cobra"
79)
810
911func createCompleteCommand (rootCmd * cobra.Command ) * cobra.Command {
10- return & cobra.Command {
11- Use : "completion" ,
12+ cmd := & cobra.Command {
13+ Use : "completion SHELL " ,
1214 Short : "Generates bash completion scripts" ,
1315 Long : `To load completion run
1416
15- . <(devcontainer completion)
17+ . <(devcontainer completion SHELL)
18+
19+ Valid values for SHELL are : bash, fish, powershell, zsh
1620
17- To configure your bash shell to load completions for each session add to your bashrc
21+ For example, to configure your bash shell to load completions for each session add to your bashrc
1822
1923 # ~/.bashrc or ~/.profile
2024 . <(devcontainer completion)
2125 ` ,
2226 Run : func (cmd * cobra.Command , args []string ) {
23- rootCmd .GenBashCompletion (os .Stdout )
27+ if len (args ) != 1 {
28+ cmd .Usage ()
29+ os .Exit (1 )
30+ }
31+ shell := args [0 ]
32+ switch strings .ToLower (shell ) {
33+ case "bash" :
34+ rootCmd .GenBashCompletion (os .Stdout )
35+ case "fish" :
36+ rootCmd .GenFishCompletion (os .Stdout , true )
37+ case "powershell" :
38+ rootCmd .GenPowerShellCompletion (os .Stdout )
39+ case "zsh" :
40+ rootCmd .GenPowerShellCompletion (os .Stdout )
41+ default :
42+ fmt .Printf ("Unsupported SHELL value: '%s'\n " , shell )
43+ cmd .Usage ()
44+ os .Exit (1 )
45+ }
2446 },
2547 }
48+ return cmd
2649}
You can’t perform that action at this time.
0 commit comments