/
print.go
48 lines (44 loc) · 1.23 KB
/
print.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 settings
import (
"fmt"
"os"
"github.com/common-fate/granted/pkg/config"
"github.com/fatih/structs"
"github.com/olekukonko/tablewriter"
"github.com/urfave/cli/v2"
)
var PrintCommand = cli.Command{
Name: "print",
Usage: "List Granted Settings",
Action: func(c *cli.Context) error {
cfg, err := config.Load()
if err != nil {
return err
}
data := [][]string{
{"update-checker-api-url", c.String("update-checker-api-url")},
}
// display config, this uses reflection to convert the config struct to a map
// it will always show all the values in the config without us having to update it
for k, v := range structs.Map(cfg) {
data = append(data, []string{k, fmt.Sprint(v)})
}
table := tablewriter.NewWriter(os.Stderr)
table.SetHeader([]string{"SETTING", "VALUE"})
table.SetAutoWrapText(false)
table.SetAutoFormatHeaders(true)
table.SetHeaderAlignment(tablewriter.ALIGN_LEFT)
table.SetAlignment(tablewriter.ALIGN_LEFT)
table.SetCenterSeparator("")
table.SetColumnSeparator("")
table.SetRowSeparator("")
table.SetRowLine(true)
table.SetHeaderLine(false)
table.SetBorder(false)
table.SetTablePadding("\t")
table.SetNoWhiteSpace(true)
table.AppendBulk(data)
table.Render()
return nil
},
}