Skip to content

Commit 2c1406e

Browse files
committed
[cherry-pick] chore(settings/print): migrate to tablewriter v1
Cherry pick fwdcloudsec#891 into the 0.38 branch.
1 parent e1f1b5a commit 2c1406e

File tree

3 files changed

+32
-21
lines changed

3 files changed

+32
-21
lines changed

go.mod

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ require (
8686
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
8787
github.com/muesli/termenv v0.15.3-0.20240618155329-98d742f6907a // indirect
8888
github.com/muhlemmer/gu v0.3.1 // indirect
89+
github.com/olekukonko/errors v1.1.0 // indirect
90+
github.com/olekukonko/ll v0.0.9 // indirect
8991
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
9092
github.com/rivo/uniseg v0.4.7 // indirect
9193
github.com/shopspring/decimal v1.2.0 // indirect
@@ -144,7 +146,7 @@ require (
144146
github.com/mattn/go-isatty v0.0.20
145147
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
146148
github.com/mtibben/percent v0.2.1 // indirect
147-
github.com/olekukonko/tablewriter v0.0.5
149+
github.com/olekukonko/tablewriter v1.0.9
148150
github.com/russross/blackfriday/v2 v2.1.0 // indirect
149151
github.com/sethvargo/go-retry v0.2.4
150152
github.com/stretchr/testify v1.10.0

go.sum

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,6 @@ github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/
258258
github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
259259
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
260260
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
261-
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
262261
github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
263262
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
264263
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
@@ -290,8 +289,12 @@ github.com/muhlemmer/httpforwarded v0.1.0/go.mod h1:yo9czKedo2pdZhoXe+yDkGVbU0TJ
290289
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
291290
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
292291
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
293-
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
294-
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
292+
github.com/olekukonko/errors v1.1.0 h1:RNuGIh15QdDenh+hNvKrJkmxxjV4hcS50Db478Ou5sM=
293+
github.com/olekukonko/errors v1.1.0/go.mod h1:ppzxA5jBKcO1vIpCXQ9ZqgDh8iwODz6OXIGKU8r5m4Y=
294+
github.com/olekukonko/ll v0.0.9 h1:Y+1YqDfVkqMWuEQMclsF9HUR5+a82+dxJuL1HHSRpxI=
295+
github.com/olekukonko/ll v0.0.9/go.mod h1:En+sEW0JNETl26+K8eZ6/W4UQ7CYSrrgg/EdIYT2H8g=
296+
github.com/olekukonko/tablewriter v1.0.9 h1:XGwRsYLC2bY7bNd93Dk51bcPZksWZmLYuaTHR0FqfL8=
297+
github.com/olekukonko/tablewriter v1.0.9/go.mod h1:5c+EBPeSqvXnLLgkm9isDdzR3wjfBkHR9Nhfp3NWrzo=
295298
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 h1:KoWmjvw+nsYOo29YJK9vDA65RGE3NrOnUtO7a+RF9HU=
296299
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8/go.mod h1:HKlIX3XHQyzLZPlr7++PzdhaXEj94dEiJgZDTsxEqUI=
297300
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=

pkg/granted/settings/print.go

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/common-fate/granted/pkg/config"
88
"github.com/fatih/structs"
99
"github.com/olekukonko/tablewriter"
10+
"github.com/olekukonko/tablewriter/tw"
1011
"github.com/urfave/cli/v2"
1112
)
1213

@@ -18,30 +19,35 @@ var PrintCommand = cli.Command{
1819
if err != nil {
1920
return err
2021
}
21-
data := [][]string{
22-
{"update-checker-api-url", c.String("update-checker-api-url")},
22+
data := []any{
23+
[]string{"update-checker-api-url", c.String("update-checker-api-url")},
2324
}
2425
// display config, this uses reflection to convert the config struct to a map
2526
// it will always show all the values in the config without us having to update it
2627
for k, v := range structs.Map(cfg) {
2728
data = append(data, []string{k, fmt.Sprint(v)})
2829
}
2930

30-
table := tablewriter.NewWriter(os.Stderr)
31-
table.SetHeader([]string{"SETTING", "VALUE"})
32-
table.SetAutoWrapText(false)
33-
table.SetAutoFormatHeaders(true)
34-
table.SetHeaderAlignment(tablewriter.ALIGN_LEFT)
35-
table.SetAlignment(tablewriter.ALIGN_LEFT)
36-
table.SetCenterSeparator("")
37-
table.SetColumnSeparator("")
38-
table.SetRowSeparator("")
39-
table.SetRowLine(true)
40-
table.SetHeaderLine(false)
41-
table.SetBorder(false)
42-
table.SetTablePadding("\t")
43-
table.SetNoWhiteSpace(true)
44-
table.AppendBulk(data)
31+
table := tablewriter.NewTable(os.Stderr,
32+
tablewriter.WithConfig(tablewriter.NewConfigBuilder().
33+
WithRowAutoWrap(tw.WrapNone).
34+
WithHeaderAutoFormat(tw.On).
35+
WithHeaderAlignment(tw.AlignLeft).
36+
WithRowAlignment(tw.AlignLeft).
37+
WithTrimSpace(tw.On).
38+
Build()),
39+
tablewriter.WithRendition(tw.Rendition{
40+
Symbols: tw.NewSymbols(tw.StyleNone),
41+
Borders: tw.BorderNone,
42+
Settings: tw.Settings{
43+
Separators: tw.Separators{
44+
BetweenRows: tw.On,
45+
},
46+
},
47+
}),
48+
)
49+
table.Header("SETTING", "VALUE")
50+
table.Bulk(data)
4551
table.Render()
4652
return nil
4753
},

0 commit comments

Comments
 (0)