Commit a336ab1f authored by Chao Xu's avatar Chao Xu

address wojtek-t's comment

parent 80a8295b
......@@ -33,15 +33,15 @@ import (
// NameSystems returns the name system used by the generators in this package.
func NameSystems() namer.NameSystems {
pluralExceptions := map[string]string{
"Endpoints": "endpoints",
"ComponentStatus": "componentStatus",
"Endpoints": "Endpoints",
"ComponentStatus": "ComponentStatus",
}
return namer.NameSystems{
"public": namer.NewPublicNamer(0),
"private": namer.NewPrivateNamer(0),
"raw": namer.NewRawNamer("", nil),
"publicPlural": namer.NewPluralNamer(pluralExceptions, true),
"privatePlural": namer.NewPluralNamer(pluralExceptions, false),
"publicPlural": namer.NewPublicPluralNamer(pluralExceptions),
"privatePlural": namer.NewPrivatePluralNamer(pluralExceptions),
}
}
......
......@@ -19,20 +19,22 @@ package namer
import "k8s.io/kubernetes/cmd/libs/go2idl/types"
type pluralNamer struct {
// key is the case-sensitive type name, value is the case-insensitive
// intended output.
exceptions map[string]string
finalize func(string) string
}
// NewPluralNamer returns a namer that returns the plural form of the input
// type's name.
func NewPluralNamer(exceptions map[string]string, public bool) *pluralNamer {
var finalize func(string) string
if public {
finalize = IC
} else {
finalize = IL
}
return &pluralNamer{exceptions, finalize}
// NewPublicPluralNamer returns a namer that returns the plural form of the input
// type's name, starting with a uppercase letter.
func NewPublicPluralNamer(exceptions map[string]string) *pluralNamer {
return &pluralNamer{exceptions, IC}
}
// NewPrivatePluralNamer returns a namer that returns the plural form of the input
// type's name, starting with a lowercase letter.
func NewPrivatePluralNamer(exceptions map[string]string) *pluralNamer {
return &pluralNamer{exceptions, IL}
}
// Name returns the plural form of the type's name. If the type's name is found
......
......@@ -27,8 +27,8 @@ func TestPluralNamer(t *testing.T) {
// The type name is already in the plural form
"Endpoints": "endpoints",
}
public := NewPluralNamer(exceptions, true)
private := NewPluralNamer(exceptions, false)
public := NewPublicPluralNamer(exceptions)
private := NewPrivatePluralNamer(exceptions)
cases := []struct {
typeName string
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment