forked from Azure/draft-classic
/
pack_list.go
42 lines (37 loc) · 924 Bytes
/
pack_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
package main
import (
"fmt"
"io"
"github.com/Azure/draft/pkg/draft/draftpath"
"github.com/Azure/draft/pkg/draft/pack"
"github.com/spf13/cobra"
)
type packListCmd struct {
out io.Writer
repo string // list packs from this repo
home draftpath.Home // $DRAFT_HOME
}
func newPackListCmd(out io.Writer) *cobra.Command {
list := &packListCmd{out: out}
cmd := &cobra.Command{
Use: "list",
Short: "list available Draft packs",
RunE: func(cmd *cobra.Command, args []string) error {
return list.run()
},
}
list.home = draftpath.Home(homePath())
cmd.Flags().StringVar(&list.repo, "repo", "", "list packs by repo (default all)")
return cmd
}
func (cmd *packListCmd) run() error {
packs, err := pack.List(cmd.home.Packs(), cmd.repo)
if err != nil {
return err
}
fmt.Fprintln(cmd.out, "Available Packs:")
for _, name := range packs {
fmt.Fprintf(cmd.out, " %s\n", name)
}
return nil
}