update the client-gen to use the plural namer

pull/6/head
Chao Xu 2015-12-10 22:31:29 -08:00
parent e2a30aba7a
commit 80a8295bce
3 changed files with 32 additions and 26 deletions

View File

@ -32,10 +32,16 @@ import (
// NameSystems returns the name system used by the generators in this package. // NameSystems returns the name system used by the generators in this package.
func NameSystems() namer.NameSystems { func NameSystems() namer.NameSystems {
pluralExceptions := map[string]string{
"Endpoints": "endpoints",
"ComponentStatus": "componentStatus",
}
return namer.NameSystems{ return namer.NameSystems{
"public": namer.NewPublicNamer(0), "public": namer.NewPublicNamer(0),
"private": namer.NewPrivateNamer(0), "private": namer.NewPrivateNamer(0),
"raw": namer.NewRawNamer("", nil), "raw": namer.NewRawNamer("", nil),
"publicPlural": namer.NewPluralNamer(pluralExceptions, true),
"privatePlural": namer.NewPluralNamer(pluralExceptions, false),
} }
} }

View File

@ -96,8 +96,8 @@ type $.Group$Client struct {
` `
var namespacerImplTemplate = ` var namespacerImplTemplate = `
func (c *$.Group$Client) $.type.Name.Name$s(namespace string) $.type.Name.Name$Interface { func (c *$.Group$Client) $.type|publicPlural$(namespace string) $.type.Name.Name$Interface {
return new$.type.Name.Name$s(c, namespace) return new$.type|publicPlural$(c, namespace)
} }
` `

View File

@ -76,7 +76,7 @@ func (g *genClientForType) GenerateType(c *generator.Context, t *types.Type, w i
var namespacerTemplate = ` var namespacerTemplate = `
// $.type|public$Namespacer has methods to work with $.type|public$ resources in a namespace // $.type|public$Namespacer has methods to work with $.type|public$ resources in a namespace
type $.type|public$Namespacer interface { type $.type|public$Namespacer interface {
$.type|public$s(namespace string) $.type|public$Interface $.type|publicPlural$(namespace string) $.type|public$Interface
} }
` `
@ -95,28 +95,28 @@ type $.type|public$Interface interface {
// template for the struct that implements the interface // template for the struct that implements the interface
var structTemplate = ` var structTemplate = `
// $.type|private$s implements $.type|public$Interface // $.type|privatePlural$ implements $.type|public$Interface
type $.type|private$s struct { type $.type|privatePlural$ struct {
client *$.Package$Client client *$.Package$Client
ns string ns string
} }
` `
var newStructTemplate = ` var newStructTemplate = `
// new$.type|public$s returns a $.type|public$s // new$.type|publicPlural$ returns a $.type|publicPlural$
func new$.type|public$s(c *ExtensionsClient, namespace string) *$.type|private$s { func new$.type|publicPlural$(c *ExtensionsClient, namespace string) *$.type|privatePlural$ {
return &$.type|private$s{ return &$.type|privatePlural${
client: c, client: c,
ns: namespace, ns: namespace,
} }
} }
` `
var listTemplate = ` var listTemplate = `
// List takes label and field selectors, and returns the list of $.type|public$s that match those selectors. // List takes label and field selectors, and returns the list of $.type|publicPlural$ that match those selectors.
func (c *$.type|private$s) List(opts $.unvListOptions|raw$) (result *$.type|raw$List, err error) { func (c *$.type|privatePlural$) List(opts $.unvListOptions|raw$) (result *$.type|raw$List, err error) {
result = &$.type|raw$List{} result = &$.type|raw$List{}
err = c.client.Get(). err = c.client.Get().
Namespace(c.ns). Namespace(c.ns).
Resource("$.type|private$s"). Resource("$.type|privatePlural$").
VersionedParams(&opts, api.Scheme). VersionedParams(&opts, api.Scheme).
Do(). Do().
Into(result) Into(result)
@ -125,11 +125,11 @@ func (c *$.type|private$s) List(opts $.unvListOptions|raw$) (result *$.type|raw$
` `
var getTemplate = ` var getTemplate = `
// Get takes name of the $.type|private$, and returns the corresponding $.type|private$ object, and an error if there is any. // Get takes name of the $.type|private$, and returns the corresponding $.type|private$ object, and an error if there is any.
func (c *$.type|private$s) Get(name string) (result *$.type|raw$, err error) { func (c *$.type|privatePlural$) Get(name string) (result *$.type|raw$, err error) {
result = &$.type|raw${} result = &$.type|raw${}
err = c.client.Get(). err = c.client.Get().
Namespace(c.ns). Namespace(c.ns).
Resource("$.type|private$s"). Resource("$.type|privatePlural$").
Name(name). Name(name).
Do(). Do().
Into(result) Into(result)
@ -139,9 +139,9 @@ func (c *$.type|private$s) Get(name string) (result *$.type|raw$, err error) {
var deleteTemplate = ` var deleteTemplate = `
// Delete takes name of the $.type|private$ and deletes it. Returns an error if one occurs. // Delete takes name of the $.type|private$ and deletes it. Returns an error if one occurs.
func (c *$.type|private$s) Delete(name string, options *$.apiDeleteOptions|raw$) error { func (c *$.type|privatePlural$) Delete(name string, options *$.apiDeleteOptions|raw$) error {
if options == nil { if options == nil {
return c.client.Delete().Namespace(c.ns).Resource("$.type|private$s").Name(name).Do().Error() return c.client.Delete().Namespace(c.ns).Resource("$.type|privatePlural$").Name(name).Do().Error()
} }
body, err := api.Scheme.EncodeToVersion(options, c.client.APIVersion()) body, err := api.Scheme.EncodeToVersion(options, c.client.APIVersion())
if err != nil { if err != nil {
@ -149,7 +149,7 @@ func (c *$.type|private$s) Delete(name string, options *$.apiDeleteOptions|raw$)
} }
return c.client.Delete(). return c.client.Delete().
Namespace(c.ns). Namespace(c.ns).
Resource("$.type|private$s"). Resource("$.type|privatePlural$").
Name(name). Name(name).
Body(body). Body(body).
Do(). Do().
@ -159,11 +159,11 @@ func (c *$.type|private$s) Delete(name string, options *$.apiDeleteOptions|raw$)
var createTemplate = ` var createTemplate = `
// Create takes the representation of a $.type|private$ and creates it. Returns the server's representation of the $.type|private$, and an error, if there is any. // Create takes the representation of a $.type|private$ and creates it. Returns the server's representation of the $.type|private$, and an error, if there is any.
func (c *$.type|private$s) Create($.type|private$ *$.type|raw$) (result *$.type|raw$, err error) { func (c *$.type|privatePlural$) Create($.type|private$ *$.type|raw$) (result *$.type|raw$, err error) {
result = &$.type|raw${} result = &$.type|raw${}
err = c.client.Post(). err = c.client.Post().
Namespace(c.ns). Namespace(c.ns).
Resource("$.type|private$s"). Resource("$.type|privatePlural$").
Body($.type|private$). Body($.type|private$).
Do(). Do().
Into(result) Into(result)
@ -173,11 +173,11 @@ func (c *$.type|private$s) Create($.type|private$ *$.type|raw$) (result *$.type|
var updateTemplate = ` var updateTemplate = `
// Update takes the representation of a $.type|private$ and updates it. Returns the server's representation of the $.type|private$, and an error, if there is any. // Update takes the representation of a $.type|private$ and updates it. Returns the server's representation of the $.type|private$, and an error, if there is any.
func (c *$.type|private$s) Update($.type|private$ *$.type|raw$) (result *$.type|raw$, err error) { func (c *$.type|privatePlural$) Update($.type|private$ *$.type|raw$) (result *$.type|raw$, err error) {
result = &$.type|raw${} result = &$.type|raw${}
err = c.client.Put(). err = c.client.Put().
Namespace(c.ns). Namespace(c.ns).
Resource("$.type|private$s"). Resource("$.type|privatePlural$").
Name($.type|private$.Name). Name($.type|private$.Name).
Body($.type|private$). Body($.type|private$).
Do(). Do().
@ -187,12 +187,12 @@ func (c *$.type|private$s) Update($.type|private$ *$.type|raw$) (result *$.type|
` `
var watchTemplate = ` var watchTemplate = `
// Watch returns a $.watchInterface|raw$ that watches the requested $.type|private$s. // Watch returns a $.watchInterface|raw$ that watches the requested $.type|privatePlural$.
func (c *$.type|private$s) Watch(opts $.unvListOptions|raw$) ($.watchInterface|raw$, error) { func (c *$.type|privatePlural$) Watch(opts $.unvListOptions|raw$) ($.watchInterface|raw$, error) {
return c.client.Get(). return c.client.Get().
Prefix("watch"). Prefix("watch").
Namespace(c.ns). Namespace(c.ns).
Resource("$.type|private$s"). Resource("$.type|privatePlural$").
VersionedParams(&opts, api.Scheme). VersionedParams(&opts, api.Scheme).
Watch() Watch()
} }