Skip to content

Commit 8302409

Browse files
committed
Add completion
1 parent 5856cf1 commit 8302409

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

cmd/devcontainer/main.go

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ func main() {
1414
var listIncludeContainerNames bool
1515
var listVerbose bool
1616

17-
var rootCmd = &cobra.Command{Use: "devcontainer"}
17+
rootCmd := &cobra.Command{Use: "devcontainer"}
1818

19-
var cmdList = &cobra.Command{
19+
cmdList := &cobra.Command{
2020
Use: "list",
2121
Short: "List devcontainers",
2222
Long: "Lists devcontainers that are currently running",
@@ -26,8 +26,26 @@ func main() {
2626
}
2727
cmdList.Flags().BoolVar(&listIncludeContainerNames, "include-container-names", false, "Also include container names in the list")
2828
cmdList.Flags().BoolVarP(&listVerbose, "verbose", "v", false, "Verbose output")
29-
3029
rootCmd.AddCommand(cmdList)
30+
31+
cmdCompletion := &cobra.Command{
32+
Use: "completion",
33+
Short: "Generates bash completion scripts",
34+
Long: `To load completion run
35+
36+
. <(devcontainer completion)
37+
38+
To configure your bash shell to load completions for each session add to your bashrc
39+
40+
# ~/.bashrc or ~/.profile
41+
. <(devcontainer completion)
42+
`,
43+
Run: func(cmd *cobra.Command, args []string) {
44+
rootCmd.GenBashCompletion(os.Stdout)
45+
},
46+
}
47+
rootCmd.AddCommand(cmdCompletion)
48+
3149
rootCmd.Execute()
3250
}
3351

0 commit comments

Comments
 (0)