diff --git a/args/args.go b/args/args.go index ad9a8348..933c3cda 100644 --- a/args/args.go +++ b/args/args.go @@ -40,10 +40,11 @@ import ( // before calling AddFlags. func Default() *GeneratorArgs { return &GeneratorArgs{ - OutputBase: DefaultSourceTree(), - GoHeaderFilePath: filepath.Join(DefaultSourceTree(), "k8s.io/gengo/boilerplate/boilerplate.go.txt"), - GeneratedBuildTag: "ignore_autogenerated", - defaultCommandLineFlags: true, + OutputBase: DefaultSourceTree(), + GoHeaderFilePath: filepath.Join(DefaultSourceTree(), "k8s.io/gengo/boilerplate/boilerplate.go.txt"), + GeneratedBuildTag: "ignore_autogenerated", + GeneratedByCommentTemplate: "// Code generated by GENERATOR_NAME. DO NOT EDIT.", + defaultCommandLineFlags: true, } } @@ -64,6 +65,11 @@ type GeneratorArgs struct { // Where to get copyright header text. GoHeaderFilePath string + // If GeneratedByCommentTemplate is set, generate a "Code generated by" comment + // above the package declaration of the format defined by this string. + // Any instances of "GENERATOR_NAME" will be replaced with the name of the code generator. + GeneratedByCommentTemplate string + // If true, only verify, don't write anything. VerifyOnly bool @@ -103,6 +109,14 @@ func (g *GeneratorArgs) LoadGoBoilerplate() ([]byte, error) { return nil, err } b = bytes.Replace(b, []byte("YEAR"), []byte(strconv.Itoa(time.Now().Year())), -1) + + if g.GeneratedByCommentTemplate != "" { + generatorPath := strings.Split(os.Args[0], "/") + generatorName := generatorPath[len(generatorPath)-1] + generatedByComment := strings.Replace(g.GeneratedByCommentTemplate, "GENERATOR_NAME", generatorName, -1) + s := fmt.Sprintf("%s\n\n", generatedByComment) + b = append(b, []byte(s)...) + } return b, nil }