-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathboot.go
59 lines (47 loc) · 1.19 KB
/
boot.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 ignite
import (
"fmt"
"os"
"sort"
"github.com/americanas-go/config"
"github.com/common-nighthawk/go-figure"
"github.com/jedib0t/go-pretty/v6/table"
)
func Boot() {
config.Load()
if config.Bool(bannerEnabled) {
fig := figure.NewColorFigure(config.String(phrase), config.String(fontName), config.String(color), config.Bool(strict))
fig.Print()
}
if config.Bool(cfgEnabled) {
var rows []table.Row
entries := config.Entries()
sort.Slice(entries[:], func(i, j int) bool {
return entries[i].Key < entries[j].Key
})
for _, entry := range entries {
v := config.Get(entry.Key)
if entry.Options.Hide {
v = "****"
}
maxLength := config.Int(maxLength)
defaultValue := fmt.Sprintf("%v", entry.Value)
if len(defaultValue) > maxLength {
defaultValue = defaultValue[:maxLength]
}
value := fmt.Sprintf("%v", v)
if len(value) > maxLength {
value = value[:maxLength]
}
rows = append(rows, table.Row{
entry.Key, defaultValue, value,
})
}
t := table.NewWriter()
t.SetOutputMirror(os.Stdout)
t.SetStyle(table.StyleColoredBright)
t.AppendHeader(table.Row{"key", "default value", "value"})
t.AppendRows(rows)
t.Render()
}
}