Skip to content

Commit 2015ae0

Browse files
authored
Merge pull request #14123 from Rabattkarte/7731-add-doc-url
Add doc URL to the addon list table
2 parents 0b58261 + c44d2e2 commit 2015ae0

File tree

13 files changed

+117
-81
lines changed

13 files changed

+117
-81
lines changed

cmd/minikube/cmd/config/addons_list.go

+31-18
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import (
3636
)
3737

3838
var addonListOutput string
39+
var addonPrintDocs bool
3940

4041
// AddonListTemplate represents the addon list template
4142
type AddonListTemplate struct {
@@ -58,7 +59,7 @@ var addonsListCmd = &cobra.Command{
5859
}
5960
switch strings.ToLower(addonListOutput) {
6061
case "list":
61-
printAddonsList(cc)
62+
printAddonsList(cc, addonPrintDocs)
6263
case "json":
6364
printAddonsJSON(cc)
6465
default:
@@ -68,13 +69,8 @@ var addonsListCmd = &cobra.Command{
6869
}
6970

7071
func init() {
71-
addonsListCmd.Flags().StringVarP(
72-
&addonListOutput,
73-
"output",
74-
"o",
75-
"list",
76-
`minikube addons list --output OUTPUT. json, list`)
77-
72+
addonsListCmd.Flags().StringVarP(&addonListOutput, "output", "o", "list", "minikube addons list --output OUTPUT. json, list")
73+
addonsListCmd.Flags().BoolVarP(&addonPrintDocs, "docs", "d", false, "If true, print web links to addons' documentation if using --output=list (default).")
7874
AddonsCmd.AddCommand(addonsListCmd)
7975
}
8076

@@ -92,39 +88,56 @@ var stringFromStatus = func(addonStatus bool) string {
9288
return "disabled"
9389
}
9490

95-
var printAddonsList = func(cc *config.ClusterConfig) {
91+
var printAddonsList = func(cc *config.ClusterConfig, printDocs bool) {
9692
addonNames := make([]string, 0, len(assets.Addons))
9793
for addonName := range assets.Addons {
9894
addonNames = append(addonNames, addonName)
9995
}
10096
sort.Strings(addonNames)
10197

102-
var tData [][]string
10398
table := tablewriter.NewWriter(os.Stdout)
10499
table.SetAutoFormatHeaders(true)
105100
table.SetBorders(tablewriter.Border{Left: true, Top: true, Right: true, Bottom: true})
106101
table.SetCenterSeparator("|")
102+
103+
// Create table header
104+
var tHeader []string
107105
if cc == nil {
108-
table.SetHeader([]string{"Addon Name", "Maintainer"})
106+
tHeader = []string{"Addon Name", "Maintainer"}
109107
} else {
110-
table.SetHeader([]string{"Addon Name", "Profile", "Status", "Maintainer"})
108+
tHeader = []string{"Addon Name", "Profile", "Status", "Maintainer"}
111109
}
110+
if printDocs {
111+
tHeader = append(tHeader, "Docs")
112+
}
113+
table.SetHeader(tHeader)
112114

115+
// Create table data
116+
var tData [][]string
117+
var temp []string
113118
for _, addonName := range addonNames {
114119
addonBundle := assets.Addons[addonName]
115120
maintainer := addonBundle.Maintainer
116121
if maintainer == "" {
117-
maintainer = "unknown (third-party)"
122+
maintainer = "3rd party (unknown)"
123+
}
124+
docs := addonBundle.Docs
125+
if docs == "" {
126+
docs = "n/a"
118127
}
119128
if cc == nil {
120-
tData = append(tData, []string{addonName, maintainer})
121-
continue
129+
temp = []string{addonName, maintainer}
130+
} else {
131+
enabled := addonBundle.IsEnabled(cc)
132+
temp = []string{addonName, cc.Name, fmt.Sprintf("%s %s", stringFromStatus(enabled), iconFromStatus(enabled)), maintainer}
122133
}
123-
enabled := addonBundle.IsEnabled(cc)
124-
tData = append(tData, []string{addonName, cc.Name, fmt.Sprintf("%s %s", stringFromStatus(enabled), iconFromStatus(enabled)), maintainer})
134+
if printDocs {
135+
temp = append(temp, docs)
136+
}
137+
tData = append(tData, temp)
125138
}
126-
127139
table.AppendBulk(tData)
140+
128141
table.Render()
129142

130143
v, _, err := config.ListProfiles()

cmd/minikube/cmd/config/addons_list_test.go

+43-32
Original file line numberDiff line numberDiff line change
@@ -27,39 +27,50 @@ import (
2727
)
2828

2929
func TestAddonsList(t *testing.T) {
30-
t.Run("NonExistingClusterTable", func(t *testing.T) {
31-
r, w, err := os.Pipe()
32-
if err != nil {
33-
t.Fatalf("failed to create pipe: %v", err)
34-
}
35-
old := os.Stdout
36-
defer func() { os.Stdout = old }()
37-
os.Stdout = w
38-
printAddonsList(nil)
39-
if err := w.Close(); err != nil {
40-
t.Fatalf("failed to close pipe: %v", err)
41-
}
42-
buf := bufio.NewScanner(r)
43-
pipeCount := 0
44-
got := ""
45-
// Pull the first 3 lines from stdout
46-
for i := 0; i < 3; i++ {
47-
if !buf.Scan() {
48-
t.Fatalf("failed to read stdout")
30+
tests := []struct {
31+
name string
32+
printDocs bool
33+
want int
34+
}{
35+
{"DisabledDocs", false, 9},
36+
{"EnabledDocs", true, 12},
37+
}
38+
39+
for _, tt := range tests {
40+
t.Run("NonExistingClusterTable"+tt.name, func(t *testing.T) {
41+
r, w, err := os.Pipe()
42+
if err != nil {
43+
t.Fatalf("failed to create pipe: %v", err)
4944
}
50-
pipeCount += strings.Count(buf.Text(), "|")
51-
got += buf.Text()
52-
}
53-
// The lines we pull should look something like
54-
// |-----------------------------|-----------------------|
55-
// | ADDON NAME | MAINTAINER |
56-
// |-----------------------------|-----------------------|
57-
// which has 9 pipes
58-
expected := 9
59-
if pipeCount != expected {
60-
t.Errorf("Expected header to have %d pipes; got = %d: %q", expected, pipeCount, got)
61-
}
62-
})
45+
old := os.Stdout
46+
defer func() { os.Stdout = old }()
47+
os.Stdout = w
48+
printAddonsList(nil, tt.printDocs)
49+
if err := w.Close(); err != nil {
50+
t.Fatalf("failed to close pipe: %v", err)
51+
}
52+
buf := bufio.NewScanner(r)
53+
pipeCount := 0
54+
got := ""
55+
// Pull the first 3 lines from stdout
56+
for i := 0; i < 3; i++ {
57+
if !buf.Scan() {
58+
t.Fatalf("failed to read stdout")
59+
}
60+
pipeCount += strings.Count(buf.Text(), "|")
61+
got += buf.Text()
62+
}
63+
// The lines we pull should look something like
64+
// |------------|------------|(------|)
65+
// | ADDON NAME | MAINTAINER |( DOCS |)
66+
// |------------|------------|(------|)
67+
// which has 9 or 12 pipes
68+
expected := tt.want
69+
if pipeCount != expected {
70+
t.Errorf("Expected header to have %d pipes; got = %d: %q", expected, pipeCount, got)
71+
}
72+
})
73+
}
6374

6475
t.Run("NonExistingClusterJSON", func(t *testing.T) {
6576
type addons struct {

0 commit comments

Comments
 (0)