Skip to content

Commit 8a8a82e

Browse files
Merge pull request #53 from Vonage/fix/table-writer
fix: update table writer library
2 parents 22ac121 + 0c8a3bf commit 8a8a82e

File tree

6 files changed

+37
-30
lines changed

6 files changed

+37
-30
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ require (
1919
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d
2020
github.com/mholt/archiver/v4 v4.0.0-alpha.8
2121
github.com/mitchellh/go-homedir v1.1.0
22+
github.com/olekukonko/tablewriter v0.0.5
2223
github.com/rhysd/go-github-selfupdate v1.2.3
2324
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06
2425
github.com/shirou/gopsutil v3.21.11+incompatible

go.sum

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stg
166166
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
167167
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
168168
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
169+
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
169170
github.com/mattn/go-runewidth v0.0.12/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
170171
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
171172
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
@@ -185,6 +186,8 @@ github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLA
185186
github.com/nwaples/rardecode/v2 v2.1.1 h1:OJaYalXdliBUXPmC8CZGQ7oZDxzX1/5mQmgn0/GASew=
186187
github.com/nwaples/rardecode/v2 v2.1.1/go.mod h1:7uz379lSxPe6j9nvzxUZ+n7mnJNgjsRNb6IbvGVHRmw=
187188
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
189+
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
190+
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
188191
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
189192
github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
190193
github.com/onsi/gomega v1.4.2/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=

vcr/app/list/list.go

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"fmt"
66

77
"github.com/MakeNowJust/heredoc"
8-
"github.com/cli/go-gh/v2/pkg/tableprinter"
8+
"github.com/olekukonko/tablewriter"
99
"github.com/spf13/cobra"
1010

1111
"vonage-cloud-runtime-cli/pkg/cmdutil"
@@ -49,7 +49,6 @@ func NewCmdAppList(f cmdutil.Factory) *cobra.Command {
4949

5050
func runList(ctx context.Context, opts *Options) error {
5151
io := opts.IOStreams()
52-
c := io.ColorScheme()
5352

5453
spinner := cmdutil.DisplaySpinnerMessageWithHandle(" Fetching applications list...")
5554
apps, err := opts.DeploymentClient().ListVonageApplications(ctx, opts.Filter)
@@ -58,18 +57,14 @@ func runList(ctx context.Context, opts *Options) error {
5857
return fmt.Errorf("failed to list Vonage applications: %w", err)
5958
}
6059

61-
tp := tableprinter.New(io.Out, io.IsStdoutTTY(), 0)
62-
tp.AddField(c.Bold("ID"), nil, nil)
63-
tp.AddField(c.Bold("Name"), nil, nil)
64-
tp.EndRow()
60+
table := tablewriter.NewWriter(io.Out)
61+
table.SetHeader([]string{"ID", "Name"})
62+
6563
for _, app := range apps.Applications {
66-
tp.AddField(app.ID, nil, nil)
67-
tp.AddField(app.Name, nil, nil)
68-
tp.EndRow()
64+
table.Append([]string{app.ID, app.Name})
6965
}
7066

71-
if err := tp.Render(); err != nil {
72-
return fmt.Errorf("error rending applications list: %w", err)
73-
}
67+
// Render the table
68+
table.Render()
7469
return nil
7570
}

vcr/app/list/list_test.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,12 @@ func TestAppList(t *testing.T) {
7676
},
7777
want: want{
7878
stdout: heredoc.Doc(`
79-
ID Name
80-
1 App One
81-
2 App Two
79+
+----+---------+
80+
| ID | NAME |
81+
+----+---------+
82+
| 1 | App One |
83+
| 2 | App Two |
84+
+----+---------+
8285
`),
8386
},
8487
},
@@ -93,7 +96,10 @@ func TestAppList(t *testing.T) {
9396
},
9497
want: want{
9598
stdout: heredoc.Doc(`
96-
ID Name
99+
+----+------+
100+
| ID | NAME |
101+
+----+------+
102+
+----+------+
97103
`),
98104
},
99105
},
@@ -108,7 +114,10 @@ func TestAppList(t *testing.T) {
108114
},
109115
want: want{
110116
stdout: heredoc.Doc(`
111-
ID Name
117+
+----+------+
118+
| ID | NAME |
119+
+----+------+
120+
+----+------+
112121
`),
113122
},
114123
},

vcr/mongo/list/list.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"vonage-cloud-runtime-cli/pkg/cmdutil"
77

88
"github.com/MakeNowJust/heredoc"
9-
"github.com/cli/cli/v2/utils"
9+
"github.com/olekukonko/tablewriter"
1010
"github.com/spf13/cobra"
1111
)
1212

@@ -56,18 +56,14 @@ func runList(ctx context.Context, opts *Options) error {
5656
return nil
5757
}
5858

59-
//nolint
60-
tp := utils.NewTablePrinter(io)
61-
tp.AddField(c.Bold("Database"), nil, nil)
62-
tp.EndRow()
59+
table := tablewriter.NewWriter(io.Out)
60+
table.SetHeader([]string{"Database"})
61+
6362
for _, db := range result {
64-
tp.AddField(db, nil, nil)
65-
tp.EndRow()
63+
table.Append([]string{db})
6664
}
6765

68-
if err := tp.Render(); err != nil {
69-
return fmt.Errorf("error rending databases: %w", err)
70-
}
66+
table.Render()
7167

7268
return nil
7369
}

vcr/mongo/list/list_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,12 @@ func TestMongoList(t *testing.T) {
4747
},
4848
want: want{
4949
stdout: heredoc.Doc(`
50-
Database
51-
TestDB1
52-
TestDB2
50+
+----------+
51+
| DATABASE |
52+
+----------+
53+
| TestDB1 |
54+
| TestDB2 |
55+
+----------+
5356
`),
5457
},
5558
},

0 commit comments

Comments
 (0)