code-generators: remove distinction of 1st and 2nd comment block for tags

This commit is contained in:
Dr. Stefan Schimanski 2017-11-07 12:51:39 +01:00
parent 3b4424ce8c
commit b0291f90d1
10 changed files with 20 additions and 20 deletions

View File

@ -163,7 +163,7 @@ func packageForGroup(gv clientgentypes.GroupVersion, typeList []*types.Type, cli
return generators
},
FilterFunc: func(c *generator.Context, t *types.Type) bool {
return util.MustParseClientGenTags(t.SecondClosestCommentLines).GenerateClient
return util.MustParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...)).GenerateClient
},
}
}
@ -345,7 +345,7 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat
} else {
// User has not specified any override for this group version.
// filter out types which dont have genclient.
if tags := util.MustParseClientGenTags(t.SecondClosestCommentLines); !tags.GenerateClient {
if tags := util.MustParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...)); !tags.GenerateClient {
continue
}
}
@ -394,7 +394,7 @@ type tagOverrideNamer struct {
}
func (n *tagOverrideNamer) Name(t *types.Type) string {
if nameOverride := extractTag(n.tagName, t.SecondClosestCommentLines); nameOverride != "" {
if nameOverride := extractTag(n.tagName, append(t.SecondClosestCommentLines, t.CommentLines...)); nameOverride != "" {
return nameOverride
}

View File

@ -79,7 +79,7 @@ func PackageForGroup(gv clientgentypes.GroupVersion, typeList []*types.Type, cli
return generators
},
FilterFunc: func(c *generator.Context, t *types.Type) bool {
return util.MustParseClientGenTags(t.SecondClosestCommentLines).GenerateClient
return util.MustParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...)).GenerateClient
},
}
}

View File

@ -73,7 +73,7 @@ func (g *genFakeForGroup) GenerateType(c *generator.Context, t *types.Type, w io
sw.Do(groupClientTemplate, m)
for _, t := range g.types {
tags, err := util.ParseClientGenTags(t.SecondClosestCommentLines)
tags, err := util.ParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...))
if err != nil {
return err
}

View File

@ -69,7 +69,7 @@ func genStatus(t *types.Type) bool {
}
}
tags := util.MustParseClientGenTags(t.SecondClosestCommentLines)
tags := util.MustParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...))
return hasStatus && !tags.NoStatus
}
@ -87,7 +87,7 @@ func hasObjectMeta(t *types.Type) bool {
func (g *genFakeForType) GenerateType(c *generator.Context, t *types.Type, w io.Writer) error {
sw := generator.NewSnippetWriter(w, c, "$", "$")
pkg := filepath.Base(t.Name.Package)
tags, err := util.ParseClientGenTags(t.SecondClosestCommentLines)
tags, err := util.ParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...))
if err != nil {
return err
}

View File

@ -105,7 +105,7 @@ func (g *genGroup) GenerateType(c *generator.Context, t *types.Type, w io.Writer
sw.Do(groupInterfaceTemplate, m)
sw.Do(groupClientTemplate, m)
for _, t := range g.types {
tags, err := util.ParseClientGenTags(t.SecondClosestCommentLines)
tags, err := util.ParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...))
if err != nil {
return err
}

View File

@ -67,14 +67,14 @@ func genStatus(t *types.Type) bool {
break
}
}
return hasStatus && !util.MustParseClientGenTags(t.SecondClosestCommentLines).NoStatus
return hasStatus && !util.MustParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...)).NoStatus
}
// GenerateType makes the body of a file implementing the individual typed client for type t.
func (g *genClientForType) GenerateType(c *generator.Context, t *types.Type, w io.Writer) error {
sw := generator.NewSnippetWriter(w, c, "$", "$")
pkg := filepath.Base(t.Name.Package)
tags, err := util.ParseClientGenTags(t.SecondClosestCommentLines)
tags, err := util.ParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...))
if err != nil {
return err
}

View File

@ -72,7 +72,7 @@ func (g *informerGenerator) GenerateType(c *generator.Context, t *types.Type, w
clientSetInterface := c.Universe.Type(types.Name{Package: g.clientSetPackage, Name: "Interface"})
informerFor := "InformerFor"
tags, err := util.ParseClientGenTags(t.SecondClosestCommentLines)
tags, err := util.ParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...))
if err != nil {
return err
}

View File

@ -71,7 +71,7 @@ func generatedBy() string {
func objectMetaForPackage(p *types.Package) (*types.Type, bool, error) {
generatingForPackage := false
for _, t := range p.Types {
if !util.MustParseClientGenTags(t.SecondClosestCommentLines).GenerateClient {
if !util.MustParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...)).GenerateClient {
continue
}
generatingForPackage = true
@ -176,7 +176,7 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat
var typesToGenerate []*types.Type
for _, t := range p.Types {
tags := util.MustParseClientGenTags(t.SecondClosestCommentLines)
tags := util.MustParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...))
if !tags.GenerateClient || tags.NoVerbs || !tags.HasVerb("list") || !tags.HasVerb("watch") {
continue
}
@ -306,7 +306,7 @@ func groupPackage(basePackage string, groupPkgName string, groupVersions clientg
return generators
},
FilterFunc: func(c *generator.Context, t *types.Type) bool {
tags := util.MustParseClientGenTags(t.SecondClosestCommentLines)
tags := util.MustParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...))
return tags.GenerateClient && tags.HasVerb("list") && tags.HasVerb("watch")
},
}
@ -349,7 +349,7 @@ func versionPackage(basePackage string, groupPkgName string, gv clientgentypes.G
return generators
},
FilterFunc: func(c *generator.Context, t *types.Type) bool {
tags := util.MustParseClientGenTags(t.SecondClosestCommentLines)
tags := util.MustParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...))
return tags.GenerateClient && tags.HasVerb("list") && tags.HasVerb("watch")
},
}

View File

@ -43,7 +43,7 @@ func (g *expansionGenerator) Filter(c *generator.Context, t *types.Type) bool {
func (g *expansionGenerator) GenerateType(c *generator.Context, t *types.Type, w io.Writer) error {
sw := generator.NewSnippetWriter(w, c, "$", "$")
for _, t := range g.types {
tags := util.MustParseClientGenTags(t.SecondClosestCommentLines)
tags := util.MustParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...))
if _, err := os.Stat(filepath.Join(g.packagePath, strings.ToLower(t.Name.Name+"_expansion.go"))); os.IsNotExist(err) {
sw.Do(expansionInterfaceTemplate, t)
if !tags.NonNamespaced {

View File

@ -118,7 +118,7 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat
var typesToGenerate []*types.Type
for _, t := range p.Types {
tags := util.MustParseClientGenTags(t.SecondClosestCommentLines)
tags := util.MustParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...))
if !tags.GenerateClient || !tags.HasVerb("list") || !tags.HasVerb("get") {
continue
}
@ -160,7 +160,7 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat
return generators
},
FilterFunc: func(c *generator.Context, t *types.Type) bool {
tags := util.MustParseClientGenTags(t.SecondClosestCommentLines)
tags := util.MustParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...))
return tags.GenerateClient && tags.HasVerb("list") && tags.HasVerb("get")
},
})
@ -174,7 +174,7 @@ func objectMetaForPackage(p *types.Package) (*types.Type, bool, error) {
generatingForPackage := false
for _, t := range p.Types {
// filter out types which dont have genclient.
if !util.MustParseClientGenTags(t.SecondClosestCommentLines).GenerateClient {
if !util.MustParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...)).GenerateClient {
continue
}
generatingForPackage = true
@ -238,7 +238,7 @@ func (g *listerGenerator) GenerateType(c *generator.Context, t *types.Type, w io
"objectMeta": g.objectMeta,
}
tags, err := util.ParseClientGenTags(t.SecondClosestCommentLines)
tags, err := util.ParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...))
if err != nil {
return err
}