@@ -302,6 +302,10 @@ type FunctionGen interface {
302
302
// Conditions returns the conditions that must true for a resource to be
303
303
// validated by this function.
304
304
Conditions () Conditions
305
+
306
+ // Comments returns optional comments that should be added to the generated
307
+ // code (without the leading "//").
308
+ Comments () []string
305
309
}
306
310
307
311
// Conditions defines what conditions must be true for a resource to be validated.
@@ -356,21 +360,42 @@ func GenericFunction(tagName string, flags FunctionFlags, function types.Name, t
356
360
return & functionGen {tagName : tagName , flags : flags , function : function , extraArgs : anyArgs , typeArgs : typeArgs }
357
361
}
358
362
363
+ // WithCondition adds a condition to a FunctionGen.
359
364
func WithCondition (fn FunctionGen , conditions Conditions ) FunctionGen {
360
365
name , args := fn .SignatureAndArgs ()
361
366
return & functionGen {
362
- tagName : fn .TagName (), flags : fn .Flags (), function : name , extraArgs : args , typeArgs : fn .TypeArgs (),
367
+ tagName : fn .TagName (),
368
+ flags : fn .Flags (),
369
+ function : name ,
370
+ extraArgs : args ,
371
+ typeArgs : fn .TypeArgs (),
372
+ comments : fn .Comments (),
363
373
conditions : conditions ,
364
374
}
365
375
}
366
376
377
+ // WithComment adds a comment to a FunctionGen.
378
+ func WithComment (fn FunctionGen , comment string ) FunctionGen {
379
+ name , args := fn .SignatureAndArgs ()
380
+ return & functionGen {
381
+ tagName : fn .TagName (),
382
+ flags : fn .Flags (),
383
+ function : name ,
384
+ extraArgs : args ,
385
+ typeArgs : fn .TypeArgs (),
386
+ comments : append (fn .Comments (), comment ),
387
+ conditions : fn .Conditions (),
388
+ }
389
+ }
390
+
367
391
type functionGen struct {
368
392
tagName string
369
393
function types.Name
370
394
extraArgs []any
371
395
typeArgs []types.Name
372
396
flags FunctionFlags
373
397
conditions Conditions
398
+ comments []string
374
399
}
375
400
376
401
func (v * functionGen ) TagName () string {
@@ -389,6 +414,8 @@ func (v *functionGen) Flags() FunctionFlags {
389
414
390
415
func (v * functionGen ) Conditions () Conditions { return v .conditions }
391
416
417
+ func (v * functionGen ) Comments () []string { return v .comments }
418
+
392
419
// Variable creates a VariableGen for a given function name and extraArgs.
393
420
func Variable (variable PrivateVar , init FunctionGen ) VariableGen {
394
421
return & variableGen {
0 commit comments