forked from gobuffalo/buffalo
/
list.go
59 lines (49 loc) · 1.13 KB
/
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
58
59
package plugins
import (
"bytes"
"fmt"
"os"
"path/filepath"
"sort"
"text/tabwriter"
pluginsin "github.com/gobuffalo/buffalo/plugins"
"github.com/spf13/cobra"
)
var listCmd = &cobra.Command{
Use: "list",
Short: "a list of installed buffalo plugins",
RunE: func(cmd *cobra.Command, args []string) error {
list, err := pluginsin.Available()
if err != nil {
return err
}
var cmds pluginsin.Commands
for _, l := range list {
for _, c := range l {
cmds = append(cmds, c)
}
}
sort.Slice(cmds, func(i, j int) bool {
c1 := cmds[i]
c2 := cmds[j]
return c1.Name+c1.Name < c2.Name+c2.Name
})
w := tabwriter.NewWriter(os.Stdout, 0, 0, 1, ' ', tabwriter.Debug)
fmt.Fprintln(w, "Bin\tCommand\tDescription")
fmt.Fprintln(w, "---\t---\t---")
for _, c := range cmds {
if c.Name == "" {
continue
}
sb := &bytes.Buffer{}
sb.WriteString("buffalo ")
if c.BuffaloCommand != "root" {
sb.WriteString(c.BuffaloCommand)
sb.WriteString(" ")
}
sb.WriteString(c.Name)
fmt.Fprintf(w, "%s\t%s\t%s\n", filepath.Base(c.Binary), sb.String(), c.Description)
}
return w.Flush()
},
}