-
Notifications
You must be signed in to change notification settings - Fork 7
/
starterkit_list.go
57 lines (47 loc) · 1.14 KB
/
starterkit_list.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package cmd
import (
"fmt"
"io"
"path/filepath"
vega "github.com/srijanone/vega/pkg/core"
"github.com/spf13/cobra"
)
type starterkitListCmd struct {
out io.Writer
home vega.Home
repo string
}
func newStarterKitListCmd(out io.Writer) *cobra.Command {
skListCmd := &starterkitListCmd{
out: out,
}
const listCmdDesc = "list starterkits"
listCmd := &cobra.Command{
Use: "list",
Short: listCmdDesc,
Long: listCmdDesc,
RunE: func(cmd *cobra.Command, args []string) error {
return skListCmd.execute()
},
}
flags := listCmd.Flags()
flags.StringVarP(&skListCmd.repo, "repo", "r", "default", "name of the starterkit repo")
skListCmd.home = vega.Home(homePath())
return listCmd
}
func (cmd *starterkitListCmd) execute() error {
path := filepath.Join(cmd.home.StarterKits(), cmd.repo)
starterkitRepo := vega.StarterKitRepo{
Name: cmd.repo,
Path: path,
}
starterkits, err := starterkitRepo.StarterKitList()
if err != nil {
return err
}
fmt.Fprintln(cmd.out, "Available starterkits:")
for _, starterkit := range starterkits {
fmt.Fprintf(cmd.out, " %10s (%s)\n", starterkit.Name, starterkit.Path)
}
return nil
}