Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Allow plural resource names.
  • Loading branch information
pwittrock committed May 14, 2018
1 parent b8eff8f commit 8a7b21b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions cmd/kubebuilder/create/resource/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ func AddCreateResource(cmd *cobra.Command) {
createResourceCmd.Flags().BoolVar(&nonNamespacedKind, "non-namespaced", false, "if set, the API kind will be non namespaced")
createResourceCmd.Flags().BoolVar(&controller, "controller", true, "if true, generate the controller code for the resource")
createResourceCmd.Flags().BoolVar(&generate, "generate", true, "generate source code")
createResourceCmd.Flags().BoolVar(&createutil.AllowPluralKind, "plural-kind", false, "allow the kind to be plural")
cmd.AddCommand(createResourceCmd)
}

Expand Down
10 changes: 7 additions & 3 deletions cmd/kubebuilder/create/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (

var (
GroupName, KindName, VersionName, ResourceName, Copyright string
AllowPluralKind bool
)

func ValidateResourceFlags() {
Expand All @@ -43,11 +44,14 @@ func ValidateResourceFlags() {
if len(KindName) == 0 {
log.Fatal("Must specify --kind")
}

rs := inflect.NewDefaultRuleset()
if len(ResourceName) == 0 {
if inflect.NewDefaultRuleset().Pluralize(KindName) == KindName {
log.Fatal("Client code generation expects singular --kind.")
if !AllowPluralKind && rs.Pluralize(KindName) == KindName && rs.Singularize(KindName) != KindName {
log.Fatalf("Client code generation expects singular --kind (e.g. %s)."+
"Or to be run with --pural-kind=true.", rs.Singularize(KindName))
}
ResourceName = inflect.NewDefaultRuleset().Pluralize(strings.ToLower(KindName))
ResourceName = rs.Pluralize(strings.ToLower(KindName))
}

groupMatch := regexp.MustCompile("^[a-z]+$")
Expand Down

0 comments on commit 8a7b21b

Please sign in to comment.