File tree Expand file tree Collapse file tree 2 files changed +47
-0
lines changed
Expand file tree Collapse file tree 2 files changed +47
-0
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ func main() {
1010
1111 rootCmd .AddCommand (createListCommand ())
1212 rootCmd .AddCommand (createExecCommand ())
13+ rootCmd .AddCommand (createTemplateCommand ())
1314 rootCmd .AddCommand (createCompleteCommand (rootCmd ))
1415
1516 rootCmd .Execute ()
Original file line number Diff line number Diff line change 1+ package main
2+
3+ import (
4+ "fmt"
5+ "io/ioutil"
6+ "os"
7+
8+ "github.com/spf13/cobra"
9+ )
10+
11+ func createTemplateCommand () * cobra.Command {
12+ cmd := & cobra.Command {
13+ Use : "template" ,
14+ Short : "work with templates" ,
15+ Long : "Use subcommands to work with devcontainer templates" ,
16+ }
17+ cmd .AddCommand (createTemplateListCommand ())
18+ return cmd
19+ }
20+
21+ func createTemplateListCommand () * cobra.Command {
22+ cmd := & cobra.Command {
23+ Use : "list" ,
24+ Short : "list templates" ,
25+ Long : "List devcontainer templates" ,
26+ Run : func (cmd * cobra.Command , args []string ) {
27+ const containerFolder string = "$HOME/source/vscode-dev-containers/containers" // TODO - make configurable!
28+
29+ folder := os .ExpandEnv (containerFolder )
30+ c , err := ioutil .ReadDir (folder )
31+ if err != nil {
32+ fmt .Printf ("Error reading devcontainer definitions: %s\n " , err )
33+ os .Exit (1 )
34+ }
35+
36+ fmt .Println ("Listing subdir/parent" )
37+ for _ , entry := range c {
38+ if entry .IsDir () {
39+ fmt .Println (entry .Name ())
40+ }
41+ }
42+
43+ },
44+ }
45+ return cmd
46+ }
You can’t perform that action at this time.
0 commit comments