@@ -114,8 +114,11 @@ func markerTemplate(marker *MarkerDoc) toHTML {
114
114
// will be added to locations marked `{{#markerdocs category name}}`.
115
115
// This allows us to put additional documentation in each category.
116
116
type MarkerDocs struct {
117
- // MarkerCategories contains the generators for which to query controller-tools.
118
- MarkerGenerators []string
117
+ // Args contains the arguments to pass to controller-gen to get
118
+ // marker help JSON output. Each key is a prefix to apply to
119
+ // category names (for disambiguation), and each value is an invocation
120
+ // of controller-gen.
121
+ Args map [string ][]string
119
122
}
120
123
121
124
func (_ MarkerDocs ) SupportsOutput (_ string ) bool { return true }
@@ -128,6 +131,11 @@ func (p MarkerDocs) Process(input *plugin.Input) error {
128
131
// first, find all categories...
129
132
markersByCategory := make (map [string ][]MarkerDoc )
130
133
for _ , cat := range markerDocs {
134
+ if cat .Category == "" {
135
+ // skip un-named categories, which are intended to be hidden
136
+ // (e.g. all the per-generate idendical output rules)
137
+ continue
138
+ }
131
139
markersByCategory [cat .Category ] = cat .Markers
132
140
}
133
141
@@ -145,10 +153,15 @@ func (p MarkerDocs) Process(input *plugin.Input) error {
145
153
return "" , fmt .Errorf ("unknown category %q" , category )
146
154
}
147
155
156
+ // HTML5 says that any characters are valid in ID except for space,
157
+ // but may not be empty (which we prevent by skipping un-named categories):
158
+ // https://www.w3.org/TR/html52/dom.html#element-attrdef-global-id
159
+ categoryAlias := strings .ReplaceAll (category , " " , "-" )
160
+
148
161
content := new (strings.Builder )
149
162
150
163
// NB(directxman12): wrap this in a div to prevent the markdown processor from inserting extra paragraphs
151
- fmt .Fprint (content , "<div><input checked type=\" checkbox\" id=\" markers-summarize\" ></input><label for=\" markers-summarize\" >Show Detailed Argument Help</label><dl class=\" markers\" >" )
164
+ fmt .Fprintf (content , "<div><input checked type=\" checkbox\" class= \" markers-summarize \" id=\" markers-summarize-%[1]s \" ></input><label class= \" markers-summarize \" for=\" markers-summarize-%[1]s \" >Show Detailed Argument Help</label><dl class=\" markers\" >" , categoryAlias )
152
165
153
166
// write the markers
154
167
for _ , marker := range markers {
@@ -204,25 +217,41 @@ func wrapWithNewlines(src string) string {
204
217
205
218
// getMarkerDocs fetches marker documentation from controller-gen
206
219
func (p MarkerDocs ) getMarkerDocs () ([]CategoryDoc , error ) {
207
- args := []string {"-wwww" } // wonderful-world-wide-web
208
- args = append (args , p .MarkerGenerators ... )
209
- cmd := exec .Command ("controller-gen" , args ... )
210
- outRaw , err := cmd .Output ()
211
- if err != nil {
212
- return nil , err
213
- }
214
-
215
220
var res []CategoryDoc
216
- if err := json .Unmarshal (outRaw , & res ); err != nil {
217
- return nil , err
221
+ for categoryPrefix , args := range p .Args {
222
+ cmd := exec .Command ("controller-gen" , args ... )
223
+ outRaw , err := cmd .Output ()
224
+ if err != nil {
225
+ return nil , err
226
+ }
227
+
228
+ var invocationRes []CategoryDoc
229
+ if err := json .Unmarshal (outRaw , & invocationRes ); err != nil {
230
+ return nil , err
231
+ }
232
+
233
+ for i , category := range invocationRes {
234
+ // leave empty categories as-is, so that they're skipped
235
+ if category .Category == "" {
236
+ continue
237
+ }
238
+ invocationRes [i ].Category = categoryPrefix + category .Category
239
+ }
240
+
241
+ res = append (res , invocationRes ... )
218
242
}
219
243
220
244
return res , nil
221
245
}
222
246
223
247
func main () {
224
248
if err := plugin .Run (MarkerDocs {
225
- MarkerGenerators : []string {"crd" , "webhook" , "rbac:roleName=cheddar" /* role name doesn't mean anything here */ , "object" },
249
+ Args : map [string ][]string {
250
+ // marker args
251
+ "" : []string {"-wwww" , "crd" , "webhook" , "rbac:roleName=cheddar" /* role name doesn't mean anything here */ , "object" },
252
+ // cli options args
253
+ "CLI: " : []string {"-hhhh" },
254
+ },
226
255
}, os .Stdin , os .Stdout , os .Args [1 :]... ); err != nil {
227
256
log .Fatal (err .Error ())
228
257
}
0 commit comments