-
Notifications
You must be signed in to change notification settings - Fork 0
/
listplugins.go
48 lines (40 loc) · 1.07 KB
/
listplugins.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
package list
import (
"sort"
"strings"
"github.com/alecthomas/kong"
"github.com/gideaworx/terraform-exporter/runner"
"github.com/olekukonko/tablewriter"
)
type ListPluginsCommand struct {
}
func (l *ListPluginsCommand) Run(context *kong.Context) error {
plugins, err := runner.LoadInstalledBOMs()
if err != nil {
return err
}
tableData := [][]string{}
sort.Slice(plugins, func(i, j int) bool {
return plugins[i].Name < plugins[j].Name
})
for _, p := range plugins {
cmdNames := []string{}
for _, c := range p.Provides {
cmdNames = append(cmdNames, c.Name)
}
sort.Strings(cmdNames)
tableData = append(tableData, []string{p.Name, p.Version.String(), strings.Join(cmdNames, ", ")})
}
table := tablewriter.NewWriter(context.Stdout)
table.SetHeader([]string{"Plugin", "Version", "Provided Exporters"})
table.SetHeaderColor(
tablewriter.Colors{tablewriter.Bold},
tablewriter.Colors{tablewriter.Bold},
tablewriter.Colors{tablewriter.Bold},
)
table.SetHeaderLine(true)
table.SetBorder(true)
table.AppendBulk(tableData)
table.Render()
return nil
}