github.com/singlemusic/buffalo@v0.16.30/buffalo/cmd/plugins/list.go (about) 1 package plugins 2 3 import ( 4 "bytes" 5 "fmt" 6 "os" 7 "path/filepath" 8 "sort" 9 "text/tabwriter" 10 11 pluginsin "github.com/gobuffalo/buffalo/plugins" 12 "github.com/spf13/cobra" 13 ) 14 15 var listCmd = &cobra.Command{ 16 Use: "list", 17 Short: "a list of installed buffalo plugins", 18 RunE: func(cmd *cobra.Command, args []string) error { 19 list, err := pluginsin.Available() 20 if err != nil { 21 return err 22 } 23 24 var cmds pluginsin.Commands 25 26 for _, l := range list { 27 for _, c := range l { 28 cmds = append(cmds, c) 29 } 30 } 31 32 sort.Slice(cmds, func(i, j int) bool { 33 c1 := cmds[i] 34 c2 := cmds[j] 35 36 return c1.Name+c1.Name < c2.Name+c2.Name 37 }) 38 39 w := tabwriter.NewWriter(os.Stdout, 0, 0, 1, ' ', tabwriter.Debug) 40 fmt.Fprintln(w, "Bin\tCommand\tDescription") 41 fmt.Fprintln(w, "---\t---\t---") 42 43 for _, c := range cmds { 44 if c.Name == "" { 45 continue 46 } 47 sb := &bytes.Buffer{} 48 sb.WriteString("buffalo ") 49 if c.BuffaloCommand != "root" { 50 sb.WriteString(c.BuffaloCommand) 51 sb.WriteString(" ") 52 } 53 sb.WriteString(c.Name) 54 fmt.Fprintf(w, "%s\t%s\t%s\n", filepath.Base(c.Binary), sb.String(), c.Description) 55 } 56 57 return w.Flush() 58 }, 59 }