Skip to content

Commit c94a035

Browse files
adding the changes for the code using table writer
1 parent 682f216 commit c94a035

File tree

3 files changed

+37
-44
lines changed

3 files changed

+37
-44
lines changed

cmd/minikube/cmd/config/addons_list.go

Lines changed: 37 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ import (
2323
"sort"
2424
"strings"
2525

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"
2828
"github.com/spf13/cobra"
2929
"k8s.io/klog/v2"
3030
"k8s.io/minikube/pkg/minikube/assets"
@@ -96,24 +96,27 @@ var printAddonsList = func(cc *config.ClusterConfig, printDocs bool) {
9696
}
9797
sort.Strings(addonNames)
9898

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)
103100

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
106107
if cc == nil {
107-
headers = table.Row{"Addon Name", "Maintainer"}
108+
tHeader = []string{"Addon Name", "Maintainer"}
108109
} else {
109-
headers = table.Row{"Addon Name", "Profile", "Status", "Maintainer"}
110+
tHeader = []string{"Addon Name", "Profile", "Status", "Maintainer"}
110111
}
111112
if printDocs {
112-
headers = append(headers, "Docs")
113+
tHeader = append(tHeader, "Docs")
113114
}
114-
t.AppendHeader(headers)
115+
table.Header(tHeader)
115116

116-
// Data
117+
// Create table data
118+
var tData [][]string
119+
var temp []string
117120
for _, addonName := range addonNames {
118121
addonBundle := assets.Addons[addonName]
119122
maintainer := addonBundle.Maintainer
@@ -124,37 +127,32 @@ var printAddonsList = func(cc *config.ClusterConfig, printDocs bool) {
124127
if docs == "" {
125128
docs = "n/a"
126129
}
127-
130+
const (
131+
green = "\033[32m"
132+
reset = "\033[0m"
133+
)
128134
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+
}
131144
}
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}
137145
if printDocs {
138-
row = append(row, docs)
146+
temp = append(temp, docs)
139147
}
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)
153155
}
154-
155-
t.Render()
156-
157-
// Suggestion for multi-profile users
158156
v, _, err := config.ListProfiles()
159157
if err != nil {
160158
klog.Errorf("list profiles returned error: %v", err)
@@ -164,8 +162,6 @@ var printAddonsList = func(cc *config.ClusterConfig, printDocs bool) {
164162
}
165163
}
166164

167-
168-
169165
var printAddonsJSON = func(cc *config.ClusterConfig) {
170166
addonNames := make([]string, 0, len(assets.Addons))
171167
for addonName := range assets.Addons {

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ require (
3333
github.com/hashicorp/go-retryablehttp v0.7.7
3434
github.com/hooklift/iso9660 v1.0.0
3535
github.com/icza/dyno v0.0.0-20230330125955-09f820a8d9c0
36-
github.com/jedib0t/go-pretty/v6 v6.6.7
3736
github.com/johanneswuerbach/nfsexports v0.0.0-20200318065542-c48c3734757f
3837
github.com/juju/clock v1.1.1
3938
github.com/juju/fslock v0.0.0-20160525022230-4d5c94c67b4b

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,8 +1090,6 @@ github.com/icza/dyno v0.0.0-20230330125955-09f820a8d9c0/go.mod h1:c1tRKs5Tx7E2+u
10901090
github.com/imdario/mergo v0.3.5/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
10911091
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
10921092
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
1093-
github.com/jedib0t/go-pretty/v6 v6.6.7 h1:m+LbHpm0aIAPLzLbMfn8dc3Ht8MW7lsSO4MPItz/Uuo=
1094-
github.com/jedib0t/go-pretty/v6 v6.6.7/go.mod h1:YwC5CE4fJ1HFUDeivSV1r//AmANFHyqczZk+U6BDALU=
10951093
github.com/jellevandenhooff/dkim v0.0.0-20150330215556-f50fe3d243e1/go.mod h1:E0B/fFc00Y+Rasa88328GlI/XbtyysCtTHZS8h7IrBU=
10961094
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
10971095
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=

0 commit comments

Comments
 (0)