Skip to content

Commit 2db4b86

Browse files
committed
add template list command
1 parent aca7cac commit 2db4b86

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

cmd/devcontainer/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff 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()

cmd/devcontainer/template.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
}

0 commit comments

Comments
 (0)