@@ -31,23 +31,21 @@ type chartTemplateData struct {
31
31
helm.ChartDocumentationInfo
32
32
HelmDocsVersion string
33
33
Values []valueRow
34
- Sections [] section
34
+ Sections sections
35
35
Files files
36
36
}
37
37
38
+ type sections struct {
39
+ DefaultSection section
40
+ Sections []section
41
+ }
42
+
38
43
type section struct {
39
44
SectionName string
40
45
SectionItems []valueRow
41
46
}
42
47
43
- func sortValueRows (valueRows []valueRow ) {
44
- sortOrder := viper .GetString ("sort-values-order" )
45
-
46
- if sortOrder != FileSortOrder && sortOrder != AlphaNumSortOrder {
47
- log .Warnf ("Invalid sort order provided %s, defaulting to %s" , sortOrder , AlphaNumSortOrder )
48
- sortOrder = AlphaNumSortOrder
49
- }
50
-
48
+ func sortValueRowsByOrder (valueRows []valueRow , sortOrder string ) {
51
49
sort .Slice (valueRows , func (i , j int ) bool {
52
50
// Globals sort above non-globals.
53
51
if valueRows [i ].IsGlobal != valueRows [j ].IsGlobal {
@@ -82,47 +80,29 @@ func sortValueRows(valueRows []valueRow) {
82
80
})
83
81
}
84
82
85
- func sortSectionedValueRows ( sectionedValueRows []section ) {
83
+ func sortValueRows ( valueRows []valueRow ) {
86
84
sortOrder := viper .GetString ("sort-values-order" )
87
85
88
86
if sortOrder != FileSortOrder && sortOrder != AlphaNumSortOrder {
89
87
log .Warnf ("Invalid sort order provided %s, defaulting to %s" , sortOrder , AlphaNumSortOrder )
90
88
sortOrder = AlphaNumSortOrder
91
89
}
92
90
93
- for _ , section := range sectionedValueRows {
94
- sort .Slice (section .SectionItems , func (i , j int ) bool {
95
- // Globals sort above non-globals.
96
- if section .SectionItems [i ].IsGlobal != section .SectionItems [j ].IsGlobal {
97
- return section .SectionItems [i ].IsGlobal
98
- }
91
+ sortValueRowsByOrder (valueRows , sortOrder )
92
+ }
99
93
100
- // Group by dependency for non-globals.
101
- if ! section .SectionItems [i ].IsGlobal && ! section .SectionItems [j ].IsGlobal {
102
- // Values for the main chart sort above values for dependencies.
103
- if (section .SectionItems [i ].Dependency == "" ) != (section .SectionItems [j ].Dependency == "" ) {
104
- return section .SectionItems [i ].Dependency == ""
105
- }
94
+ func sortSectionedValueRows (sectionedValueRows sections ) {
95
+ sortOrder := viper .GetString ("sort-values-order" )
106
96
107
- // Group dependency values together.
108
- if section .SectionItems [i ].Dependency != section .SectionItems [j ].Dependency {
109
- return section .SectionItems [i ].Dependency < section .SectionItems [j ].Dependency
110
- }
111
- }
97
+ if sortOrder != FileSortOrder && sortOrder != AlphaNumSortOrder {
98
+ log .Warnf ("Invalid sort order provided %s, defaulting to %s" , sortOrder , AlphaNumSortOrder )
99
+ sortOrder = AlphaNumSortOrder
100
+ }
112
101
113
- // Sort the remaining values within the same section.SectionItems using the configured sort order.
114
- switch sortOrder {
115
- case FileSortOrder :
116
- if section .SectionItems [i ].LineNumber == section .SectionItems [j ].LineNumber {
117
- return section .SectionItems [i ].Column < section .SectionItems [j ].Column
118
- }
119
- return section .SectionItems [i ].LineNumber < section .SectionItems [j ].LineNumber
120
- case AlphaNumSortOrder :
121
- return section .SectionItems [i ].Key < section .SectionItems [j ].Key
122
- default :
123
- panic ("cannot get here" )
124
- }
125
- })
102
+ sortValueRowsByOrder (sectionedValueRows .DefaultSection .SectionItems , sortOrder )
103
+
104
+ for _ , section := range sectionedValueRows .Sections {
105
+ sortValueRowsByOrder (section .SectionItems , sortOrder )
126
106
}
127
107
}
128
108
@@ -143,30 +123,30 @@ func getUnsortedValueRows(document *yaml.Node, descriptions map[string]helm.Char
143
123
return createValueRowsFromField ("" , nil , document .Content [0 ], descriptions , true )
144
124
}
145
125
146
- func getUnsortedSectionedValueRows (valueRows []valueRow ) [] section {
147
- var valueRowsSectionSorted [] section
148
- valueRowsSectionSorted = append ( valueRowsSectionSorted , section {
149
- SectionName : "General " ,
126
+ func getSectionedValueRows (valueRows []valueRow ) sections {
127
+ var valueRowsSectionSorted sections
128
+ valueRowsSectionSorted . DefaultSection = section {
129
+ SectionName : "Other Values " ,
150
130
SectionItems : []valueRow {},
151
- })
131
+ }
152
132
153
133
for _ , row := range valueRows {
154
134
if row .Section == "" {
155
- valueRowsSectionSorted [ 0 ]. SectionItems = append (valueRowsSectionSorted [ 0 ] .SectionItems , row )
135
+ valueRowsSectionSorted . DefaultSection . SectionItems = append (valueRowsSectionSorted . DefaultSection .SectionItems , row )
156
136
continue
157
137
}
158
138
159
139
containsSection := false
160
- for i , section := range valueRowsSectionSorted {
140
+ for i , section := range valueRowsSectionSorted . Sections {
161
141
if section .SectionName == row .Section {
162
142
containsSection = true
163
- valueRowsSectionSorted [i ].SectionItems = append (valueRowsSectionSorted [i ].SectionItems , row )
143
+ valueRowsSectionSorted . Sections [i ].SectionItems = append (valueRowsSectionSorted . Sections [i ].SectionItems , row )
164
144
break
165
145
}
166
146
}
167
147
168
148
if ! containsSection {
169
- valueRowsSectionSorted = append (valueRowsSectionSorted , section {
149
+ valueRowsSectionSorted . Sections = append (valueRowsSectionSorted . Sections , section {
170
150
SectionName : row .Section ,
171
151
SectionItems : []valueRow {row },
172
152
})
@@ -219,7 +199,7 @@ func getChartTemplateData(info helm.ChartDocumentationInfo, helmDocsVersion stri
219
199
}
220
200
221
201
sortValueRows (valuesTableRows )
222
- valueRowsSectionSorted := getUnsortedSectionedValueRows (valuesTableRows )
202
+ valueRowsSectionSorted := getSectionedValueRows (valuesTableRows )
223
203
sortSectionedValueRows (valueRowsSectionSorted )
224
204
225
205
files , err := getFiles (info .ChartDirectory )
0 commit comments