@@ -40,43 +40,14 @@ type section struct {
40
40
SectionItems []valueRow
41
41
}
42
42
43
- func sortValueRows (valueRows []valueRow ) ([] valueRow , [] section ) {
43
+ func sortValueRows (valueRows []valueRow ) {
44
44
sortOrder := viper .GetString ("sort-values-order" )
45
45
46
46
if sortOrder != FileSortOrder && sortOrder != AlphaNumSortOrder {
47
47
log .Warnf ("Invalid sort order provided %s, defaulting to %s" , sortOrder , AlphaNumSortOrder )
48
48
sortOrder = AlphaNumSortOrder
49
49
}
50
50
51
- var valueRowsSectionSorted []section
52
- valueRowsSectionSorted = append (valueRowsSectionSorted , section {
53
- SectionName : "General" ,
54
- SectionItems : []valueRow {},
55
- })
56
-
57
- for _ , row := range valueRows {
58
- if row .Section == "" {
59
- valueRowsSectionSorted [0 ].SectionItems = append (valueRowsSectionSorted [0 ].SectionItems , row )
60
- continue
61
- }
62
-
63
- containsSection := false
64
- for i , section := range valueRowsSectionSorted {
65
- if section .SectionName == row .Section {
66
- containsSection = true
67
- valueRowsSectionSorted [i ].SectionItems = append (valueRowsSectionSorted [i ].SectionItems , row )
68
- break
69
- }
70
- }
71
-
72
- if ! containsSection {
73
- valueRowsSectionSorted = append (valueRowsSectionSorted , section {
74
- SectionName : row .Section ,
75
- SectionItems : []valueRow {row },
76
- })
77
- }
78
- }
79
-
80
51
sort .Slice (valueRows , func (i , j int ) bool {
81
52
// Globals sort above non-globals.
82
53
if valueRows [i ].IsGlobal != valueRows [j ].IsGlobal {
@@ -109,8 +80,17 @@ func sortValueRows(valueRows []valueRow) ([]valueRow, []section) {
109
80
panic ("cannot get here" )
110
81
}
111
82
})
83
+ }
84
+
85
+ func sortSectionedValueRows (sectionedValueRows []section ) {
86
+ sortOrder := viper .GetString ("sort-values-order" )
87
+
88
+ if sortOrder != FileSortOrder && sortOrder != AlphaNumSortOrder {
89
+ log .Warnf ("Invalid sort order provided %s, defaulting to %s" , sortOrder , AlphaNumSortOrder )
90
+ sortOrder = AlphaNumSortOrder
91
+ }
112
92
113
- for _ , section := range valueRowsSectionSorted {
93
+ for _ , section := range sectionedValueRows {
114
94
sort .Slice (section .SectionItems , func (i , j int ) bool {
115
95
// Globals sort above non-globals.
116
96
if section .SectionItems [i ].IsGlobal != section .SectionItems [j ].IsGlobal {
@@ -144,7 +124,6 @@ func sortValueRows(valueRows []valueRow) ([]valueRow, []section) {
144
124
}
145
125
})
146
126
}
147
- return valueRows , valueRowsSectionSorted
148
127
}
149
128
150
129
func getUnsortedValueRows (document * yaml.Node , descriptions map [string ]helm.ChartValueDescription ) ([]valueRow , error ) {
@@ -164,6 +143,39 @@ func getUnsortedValueRows(document *yaml.Node, descriptions map[string]helm.Char
164
143
return createValueRowsFromField ("" , nil , document .Content [0 ], descriptions , true )
165
144
}
166
145
146
+ func getUnsortedSectionedValueRows (valueRows []valueRow ) []section {
147
+ var valueRowsSectionSorted []section
148
+ valueRowsSectionSorted = append (valueRowsSectionSorted , section {
149
+ SectionName : "General" ,
150
+ SectionItems : []valueRow {},
151
+ })
152
+
153
+ for _ , row := range valueRows {
154
+ if row .Section == "" {
155
+ valueRowsSectionSorted [0 ].SectionItems = append (valueRowsSectionSorted [0 ].SectionItems , row )
156
+ continue
157
+ }
158
+
159
+ containsSection := false
160
+ for i , section := range valueRowsSectionSorted {
161
+ if section .SectionName == row .Section {
162
+ containsSection = true
163
+ valueRowsSectionSorted [i ].SectionItems = append (valueRowsSectionSorted [i ].SectionItems , row )
164
+ break
165
+ }
166
+ }
167
+
168
+ if ! containsSection {
169
+ valueRowsSectionSorted = append (valueRowsSectionSorted , section {
170
+ SectionName : row .Section ,
171
+ SectionItems : []valueRow {row },
172
+ })
173
+ }
174
+ }
175
+
176
+ return valueRowsSectionSorted
177
+ }
178
+
167
179
func getChartTemplateData (info helm.ChartDocumentationInfo , helmDocsVersion string , dependencyValues []DependencyValues ) (chartTemplateData , error ) {
168
180
valuesTableRows , err := getUnsortedValueRows (info .ChartValues , info .ChartValuesDescriptions )
169
181
if err != nil {
@@ -206,7 +218,9 @@ func getChartTemplateData(info helm.ChartDocumentationInfo, helmDocsVersion stri
206
218
}
207
219
}
208
220
209
- valueRowsSorted , valueRowsSectionSorted := sortValueRows (valuesTableRows )
221
+ sortValueRows (valuesTableRows )
222
+ valueRowsSectionSorted := getUnsortedSectionedValueRows (valuesTableRows )
223
+ sortSectionedValueRows (valueRowsSectionSorted )
210
224
211
225
files , err := getFiles (info .ChartDirectory )
212
226
if err != nil {
@@ -216,7 +230,7 @@ func getChartTemplateData(info helm.ChartDocumentationInfo, helmDocsVersion stri
216
230
return chartTemplateData {
217
231
ChartDocumentationInfo : info ,
218
232
HelmDocsVersion : helmDocsVersion ,
219
- Values : valueRowsSorted ,
233
+ Values : valuesTableRows ,
220
234
Sections : valueRowsSectionSorted ,
221
235
Files : files ,
222
236
}, nil
0 commit comments