github.com/Azure/draft-classic@v0.16.0/cmd/draft/pack_list.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "io" 6 7 "github.com/Azure/draft/pkg/draft/draftpath" 8 "github.com/Azure/draft/pkg/draft/pack" 9 "github.com/spf13/cobra" 10 ) 11 12 type packListCmd struct { 13 out io.Writer 14 repo string // list packs from this repo 15 home draftpath.Home // $DRAFT_HOME 16 } 17 18 func newPackListCmd(out io.Writer) *cobra.Command { 19 list := &packListCmd{out: out} 20 cmd := &cobra.Command{ 21 Use: "list", 22 Short: "list available Draft packs", 23 RunE: func(cmd *cobra.Command, args []string) error { 24 return list.run() 25 }, 26 } 27 list.home = draftpath.Home(homePath()) 28 cmd.Flags().StringVar(&list.repo, "repo", "", "list packs by repo (default all)") 29 return cmd 30 } 31 32 func (cmd *packListCmd) run() error { 33 packs, err := pack.List(cmd.home.Packs(), cmd.repo) 34 if err != nil { 35 return err 36 } 37 fmt.Fprintln(cmd.out, "Available Packs:") 38 for _, name := range packs { 39 fmt.Fprintf(cmd.out, " %s\n", name) 40 } 41 return nil 42 }