@@ -23,8 +23,8 @@ import (
23
23
"sort"
24
24
"strings"
25
25
26
- "github.com/jedib0t/go-pretty/v6/table "
27
- "github.com/jedib0t/go-pretty/v6/text "
26
+ "github.com/olekukonko/tablewriter "
27
+ "github.com/olekukonko/tablewriter/tw "
28
28
"github.com/spf13/cobra"
29
29
"k8s.io/klog/v2"
30
30
"k8s.io/minikube/pkg/minikube/assets"
@@ -96,24 +96,27 @@ var printAddonsList = func(cc *config.ClusterConfig, printDocs bool) {
96
96
}
97
97
sort .Strings (addonNames )
98
98
99
- t := table .NewWriter ()
100
- t .SetStyle (table .StyleLight )
101
- t .SetOutputMirror (os .Stdout )
102
- t .Style ().Options .SeparateRows = true
99
+ table := tablewriter .NewWriter (os .Stdout )
103
100
104
- // Header
105
- var headers table.Row
101
+ table .Options (
102
+ tablewriter .WithHeaderAutoFormat (tw .On ),
103
+ )
104
+
105
+ // Create table header
106
+ var tHeader []string
106
107
if cc == nil {
107
- headers = table. Row {"Addon Name" , "Maintainer" }
108
+ tHeader = [] string {"Addon Name" , "Maintainer" }
108
109
} else {
109
- headers = table. Row {"Addon Name" , "Profile" , "Status" , "Maintainer" }
110
+ tHeader = [] string {"Addon Name" , "Profile" , "Status" , "Maintainer" }
110
111
}
111
112
if printDocs {
112
- headers = append (headers , "Docs" )
113
+ tHeader = append (tHeader , "Docs" )
113
114
}
114
- t . AppendHeader ( headers )
115
+ table . Header ( tHeader )
115
116
116
- // Data
117
+ // Create table data
118
+ var tData [][]string
119
+ var temp []string
117
120
for _ , addonName := range addonNames {
118
121
addonBundle := assets .Addons [addonName ]
119
122
maintainer := addonBundle .Maintainer
@@ -124,37 +127,32 @@ var printAddonsList = func(cc *config.ClusterConfig, printDocs bool) {
124
127
if docs == "" {
125
128
docs = "n/a"
126
129
}
127
-
130
+ const (
131
+ green = "\033 [32m"
132
+ reset = "\033 [0m"
133
+ )
128
134
if cc == nil {
129
- t .AppendRow (table.Row {addonName , maintainer })
130
- continue
135
+ temp = []string {addonName , maintainer }
136
+ } else {
137
+ enabled := addonBundle .IsEnabled (cc )
138
+ if enabled {
139
+ status := fmt .Sprintf ("%s%s %s%s" , green , stringFromStatus (enabled ), iconFromStatus (enabled ), reset )
140
+ temp = []string {fmt .Sprintf ("%s%s%s" , green , addonName , reset ), fmt .Sprintf ("%s%s%s" , green , cc .Name , reset ),status , fmt .Sprintf ("%s%s%s" , green , maintainer , reset )}
141
+ }else {
142
+ temp = []string {addonName ,cc .Name ,"" ,maintainer }
143
+ }
131
144
}
132
-
133
- enabled := addonBundle .IsEnabled (cc )
134
- statusStr := fmt .Sprintf ("%s %s" , stringFromStatus (enabled ), iconFromStatus (enabled ))
135
-
136
- row := table.Row {addonName , cc .Name , statusStr , maintainer }
137
145
if printDocs {
138
- row = append (row , docs )
146
+ temp = append (temp , docs )
139
147
}
140
-
141
- if enabled {
142
- // Color entire row green
143
- for i := range row {
144
- row [i ] = text .FgGreen .Sprintf ("%v" , row [i ])
145
- }
146
- }else {
147
- // Color entire row red
148
- for i := range row {
149
- row [i ] = text .FgRed .Sprintf ("%v" , row [i ])
150
- }
151
- }
152
- t .AppendRow (row )
148
+ tData = append (tData , temp )
149
+ }
150
+ if err := table .Bulk (tData ); err != nil {
151
+ klog .Error ("Error rendering table (bulk)" , err )
152
+ }
153
+ if err := table .Render (); err != nil {
154
+ klog .Error ("Error rendering table" , err )
153
155
}
154
-
155
- t .Render ()
156
-
157
- // Suggestion for multi-profile users
158
156
v , _ , err := config .ListProfiles ()
159
157
if err != nil {
160
158
klog .Errorf ("list profiles returned error: %v" , err )
@@ -164,8 +162,6 @@ var printAddonsList = func(cc *config.ClusterConfig, printDocs bool) {
164
162
}
165
163
}
166
164
167
-
168
-
169
165
var printAddonsJSON = func (cc * config.ClusterConfig ) {
170
166
addonNames := make ([]string , 0 , len (assets .Addons ))
171
167
for addonName := range assets .Addons {
0 commit comments