address wojtek-t's comment

This commit is contained in:
Chao Xu 2015-12-11 10:24:30 -08:00
parent 80a8295bce
commit a336ab1f3d
3 changed files with 18 additions and 16 deletions

View File

@ -33,15 +33,15 @@ 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{ pluralExceptions := map[string]string{
"Endpoints": "endpoints", "Endpoints": "Endpoints",
"ComponentStatus": "componentStatus", "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), "publicPlural": namer.NewPublicPluralNamer(pluralExceptions),
"privatePlural": namer.NewPluralNamer(pluralExceptions, false), "privatePlural": namer.NewPrivatePluralNamer(pluralExceptions),
} }
} }

View File

@ -19,20 +19,22 @@ package namer
import "k8s.io/kubernetes/cmd/libs/go2idl/types" import "k8s.io/kubernetes/cmd/libs/go2idl/types"
type pluralNamer struct { type pluralNamer struct {
// key is the case-sensitive type name, value is the case-insensitive
// intended output.
exceptions map[string]string exceptions map[string]string
finalize func(string) string finalize func(string) string
} }
// NewPluralNamer returns a namer that returns the plural form of the input // NewPublicPluralNamer returns a namer that returns the plural form of the input
// type's name. // type's name, starting with a uppercase letter.
func NewPluralNamer(exceptions map[string]string, public bool) *pluralNamer { func NewPublicPluralNamer(exceptions map[string]string) *pluralNamer {
var finalize func(string) string return &pluralNamer{exceptions, IC}
if public { }
finalize = IC
} else { // NewPrivatePluralNamer returns a namer that returns the plural form of the input
finalize = IL // type's name, starting with a lowercase letter.
} func NewPrivatePluralNamer(exceptions map[string]string) *pluralNamer {
return &pluralNamer{exceptions, finalize} return &pluralNamer{exceptions, IL}
} }
// Name returns the plural form of the type's name. If the type's name is found // Name returns the plural form of the type's name. If the type's name is found

View File

@ -27,8 +27,8 @@ func TestPluralNamer(t *testing.T) {
// The type name is already in the plural form // The type name is already in the plural form
"Endpoints": "endpoints", "Endpoints": "endpoints",
} }
public := NewPluralNamer(exceptions, true) public := NewPublicPluralNamer(exceptions)
private := NewPluralNamer(exceptions, false) private := NewPrivatePluralNamer(exceptions)
cases := []struct { cases := []struct {
typeName string typeName string