diff --git a/examples/pkg/apis/example/register.go b/examples/pkg/apis/example/register.go index e6989b21..1a2eb513 100644 --- a/examples/pkg/apis/example/register.go +++ b/examples/pkg/apis/example/register.go @@ -24,15 +24,15 @@ import ( const GroupName = "example.dev" -// SchemeGroupVersion is group version used to register these objects +// SchemeGroupVersion is group version used to register these objects. var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: runtime.APIVersionInternal} -// Kind takes an unqualified kind and returns back a Group qualified GroupKind +// Kind takes an unqualified kind and returns back a Group qualified GroupKind. func Kind(kind string) schema.GroupKind { return SchemeGroupVersion.WithKind(kind).GroupKind() } -// Resource takes an unqualified resource and returns a Group qualified GroupResource +// Resource takes an unqualified resource and returns a Group qualified GroupResource. func Resource(resource string) schema.GroupResource { return SchemeGroupVersion.WithResource(resource).GroupResource() } diff --git a/examples/pkg/apis/example/v1/register.go b/examples/pkg/apis/example/v1/register.go index c1db9897..19836585 100644 --- a/examples/pkg/apis/example/v1/register.go +++ b/examples/pkg/apis/example/v1/register.go @@ -24,15 +24,15 @@ import ( "acme.corp/pkg/apis/example" ) -// SchemeGroupVersion is group version used to register these objects +// SchemeGroupVersion is group version used to register these objects. var SchemeGroupVersion = schema.GroupVersion{Group: example.GroupName, Version: "v1"} -// Kind takes an unqualified kind and returns back a Group qualified GroupKind +// Kind takes an unqualified kind and returns back a Group qualified GroupKind. func Kind(kind string) schema.GroupKind { return SchemeGroupVersion.WithKind(kind).GroupKind() } -// Resource takes an unqualified resource and returns a Group qualified GroupResource +// Resource takes an unqualified resource and returns a Group qualified GroupResource. func Resource(resource string) schema.GroupResource { return SchemeGroupVersion.WithResource(resource).GroupResource() } diff --git a/examples/pkg/apis/example/v1alpha1/register.go b/examples/pkg/apis/example/v1alpha1/register.go index 6cf9e5b3..731c8458 100644 --- a/examples/pkg/apis/example/v1alpha1/register.go +++ b/examples/pkg/apis/example/v1alpha1/register.go @@ -24,15 +24,15 @@ import ( "acme.corp/pkg/apis/example" ) -// SchemeGroupVersion is group version used to register these objects +// SchemeGroupVersion is group version used to register these objects. var SchemeGroupVersion = schema.GroupVersion{Group: example.GroupName, Version: "v1alpha1"} -// Kind takes an unqualified kind and returns back a Group qualified GroupKind +// Kind takes an unqualified kind and returns back a Group qualified GroupKind. func Kind(kind string) schema.GroupKind { return SchemeGroupVersion.WithKind(kind).GroupKind() } -// Resource takes an unqualified resource and returns a Group qualified GroupResource +// Resource takes an unqualified resource and returns a Group qualified GroupResource. func Resource(resource string) schema.GroupResource { return SchemeGroupVersion.WithResource(resource).GroupResource() } diff --git a/examples/pkg/apis/example/v1beta1/register.go b/examples/pkg/apis/example/v1beta1/register.go index 352a5037..23d0953b 100644 --- a/examples/pkg/apis/example/v1beta1/register.go +++ b/examples/pkg/apis/example/v1beta1/register.go @@ -24,15 +24,15 @@ import ( "acme.corp/pkg/apis/example" ) -// SchemeGroupVersion is group version used to register these objects +// SchemeGroupVersion is group version used to register these objects. var SchemeGroupVersion = schema.GroupVersion{Group: example.GroupName, Version: "v1beta1"} -// Kind takes an unqualified kind and returns back a Group qualified GroupKind +// Kind takes an unqualified kind and returns back a Group qualified GroupKind. func Kind(kind string) schema.GroupKind { return SchemeGroupVersion.WithKind(kind).GroupKind() } -// Resource takes an unqualified resource and returns a Group qualified GroupResource +// Resource takes an unqualified resource and returns a Group qualified GroupResource. func Resource(resource string) schema.GroupResource { return SchemeGroupVersion.WithResource(resource).GroupResource() } diff --git a/examples/pkg/apis/example/v2/register.go b/examples/pkg/apis/example/v2/register.go index 907ec623..5025d966 100644 --- a/examples/pkg/apis/example/v2/register.go +++ b/examples/pkg/apis/example/v2/register.go @@ -24,15 +24,15 @@ import ( "acme.corp/pkg/apis/example" ) -// SchemeGroupVersion is group version used to register these objects +// SchemeGroupVersion is group version used to register these objects. var SchemeGroupVersion = schema.GroupVersion{Group: example.GroupName, Version: "v2"} -// Kind takes an unqualified kind and returns back a Group qualified GroupKind +// Kind takes an unqualified kind and returns back a Group qualified GroupKind. func Kind(kind string) schema.GroupKind { return SchemeGroupVersion.WithKind(kind).GroupKind() } -// Resource takes an unqualified resource and returns a Group qualified GroupResource +// Resource takes an unqualified resource and returns a Group qualified GroupResource. func Resource(resource string) schema.GroupResource { return SchemeGroupVersion.WithResource(resource).GroupResource() } diff --git a/examples/pkg/apis/example3/v1/register.go b/examples/pkg/apis/example3/v1/register.go index 44c15dfd..be7ae215 100644 --- a/examples/pkg/apis/example3/v1/register.go +++ b/examples/pkg/apis/example3/v1/register.go @@ -24,15 +24,15 @@ import ( example "acme.corp/pkg/apis/example3" ) -// SchemeGroupVersion is group version used to register these objects +// SchemeGroupVersion is group version used to register these objects. var SchemeGroupVersion = schema.GroupVersion{Group: example.GroupName, Version: "v1"} -// Kind takes an unqualified kind and returns back a Group qualified GroupKind +// Kind takes an unqualified kind and returns back a Group qualified GroupKind. func Kind(kind string) schema.GroupKind { return SchemeGroupVersion.WithKind(kind).GroupKind() } -// Resource takes an unqualified resource and returns a Group qualified GroupResource +// Resource takes an unqualified resource and returns a Group qualified GroupResource. func Resource(resource string) schema.GroupResource { return SchemeGroupVersion.WithResource(resource).GroupResource() } diff --git a/examples/pkg/apis/existinginterfaces/v1/register.go b/examples/pkg/apis/existinginterfaces/v1/register.go index e15c0058..f9542b06 100644 --- a/examples/pkg/apis/existinginterfaces/v1/register.go +++ b/examples/pkg/apis/existinginterfaces/v1/register.go @@ -24,15 +24,15 @@ import ( "acme.corp/pkg/apis/existinginterfaces" ) -// SchemeGroupVersion is group version used to register these objects +// SchemeGroupVersion is group version used to register these objects. var SchemeGroupVersion = schema.GroupVersion{Group: existinginterfaces.GroupName, Version: "v1"} -// Kind takes an unqualified kind and returns back a Group qualified GroupKind +// Kind takes an unqualified kind and returns back a Group qualified GroupKind. func Kind(kind string) schema.GroupKind { return SchemeGroupVersion.WithKind(kind).GroupKind() } -// Resource takes an unqualified resource and returns a Group qualified GroupResource +// Resource takes an unqualified resource and returns a Group qualified GroupResource. func Resource(resource string) schema.GroupResource { return SchemeGroupVersion.WithResource(resource).GroupResource() } diff --git a/examples/pkg/apis/secondexample/v1/register.go b/examples/pkg/apis/secondexample/v1/register.go index 4b139992..62c94758 100644 --- a/examples/pkg/apis/secondexample/v1/register.go +++ b/examples/pkg/apis/secondexample/v1/register.go @@ -24,15 +24,15 @@ import ( example "acme.corp/pkg/apis/secondexample" ) -// SchemeGroupVersion is group version used to register these objects +// SchemeGroupVersion is group version used to register these objects. var SchemeGroupVersion = schema.GroupVersion{Group: example.GroupName, Version: "v1"} -// Kind takes an unqualified kind and returns back a Group qualified GroupKind +// Kind takes an unqualified kind and returns back a Group qualified GroupKind. func Kind(kind string) schema.GroupKind { return SchemeGroupVersion.WithKind(kind).GroupKind() } -// Resource takes an unqualified resource and returns a Group qualified GroupResource +// Resource takes an unqualified resource and returns a Group qualified GroupResource. func Resource(resource string) schema.GroupResource { return SchemeGroupVersion.WithResource(resource).GroupResource() } diff --git a/main.go b/main.go index d8e9d7ed..5e286837 100644 --- a/main.go +++ b/main.go @@ -55,7 +55,7 @@ var ( // them names for use on the command line. // Each output rule turns into two command line options: // - output::
(per-generator output) - // - output: (default output) + // - output: (default output). allOutputRules = map[string]genall.OutputRule{ "dir": genall.OutputToDirectory(""), "none": genall.OutputToNothing, @@ -63,13 +63,13 @@ var ( "artifacts": genall.OutputArtifacts{}, } - // optionsRegistry contains all the marker definitions used to process command line options + // optionsRegistry contains all the marker definitions used to process command line options. optionsRegistry = &markers.Registry{} ) func init() { for genName, gen := range allGenerators { - // make the generator options marker itself + // make the generator options marker itself. defn := markers.Must(markers.MakeDefinition(genName, markers.DescribesPackage, gen)) if err := optionsRegistry.Register(defn); err != nil { panic(err) @@ -80,7 +80,7 @@ func init() { } } - // make per-generation output rule markers + // make per-generation output rule markers. for ruleName, rule := range allOutputRules { ruleMarker := markers.Must(markers.MakeDefinition(fmt.Sprintf("output:%s:%s", genName, ruleName), markers.DescribesPackage, rule)) if err := optionsRegistry.Register(ruleMarker); err != nil { @@ -94,7 +94,7 @@ func init() { } } - // make "default output" output rule markers + // make "default output" output rule markers. for ruleName, rule := range allOutputRules { ruleMarker := markers.Must(markers.MakeDefinition("output:"+ruleName, markers.DescribesPackage, rule)) if err := optionsRegistry.Register(ruleMarker); err != nil { @@ -107,7 +107,7 @@ func init() { } } - // add in the common options markers + // add in the common options markers. if err := genall.RegisterOptionsMarkers(optionsRegistry); err != nil { panic(err) } @@ -143,23 +143,23 @@ func main() { code-generator lister -ww `, RunE: func(c *cobra.Command, rawOpts []string) error { - // print version if asked for it + // print version if asked for it. if showVersion { version.Print() return nil } - // print the help if we asked for it (since we've got a different help flag :-/), then bail + // print the help if we asked for it (since we've got a different help flag :-/), then bail. if helpLevel > 0 { return c.Usage() } - // print the marker docs if we asked for them, then bail + // print the marker docs if we asked for them, then bail. if whichLevel > 0 { return printMarkerDocs(c, rawOpts, whichLevel) } - // otherwise, set up the runtime for actually running the generators + // otherwise, set up the runtime for actually running the generators. rt, err := genall.FromOptions(optionsRegistry, rawOpts) if err != nil { return err @@ -174,7 +174,7 @@ func main() { } return nil }, - SilenceUsage: true, // silence the usage, then print it out ourselves if it wasn't suppressed + SilenceUsage: true, // silence the usage, then print it out ourselves if it wasn't suppressed. } cmd.Flags().CountVarP(&whichLevel, "which-markers", "w", "print out all markers available with the requested generators\n(up to -www for the most detailed output, or -wwww for json output)") cmd.Flags().CountVarP(&helpLevel, "detailed-help", "h", "print out more detailed help\n(up to -hhh for the most detailed output, or -hhhh for json output)") @@ -194,7 +194,7 @@ func main() { if err := cmd.Execute(); err != nil { if _, noUsage := err.(noUsageError); !noUsage { - // print the usage unless we suppressed it + // print the usage unless we suppressed it. if err := cmd.Usage(); err != nil { panic(err) } diff --git a/pkg/flag/flags.go b/pkg/flag/flags.go index e6f2a096..552f016b 100644 --- a/pkg/flag/flags.go +++ b/pkg/flag/flags.go @@ -22,7 +22,7 @@ import ( "github.com/spf13/pflag" ) -// Flags - Options accepted by generator +// Flags are options accepted by the generator. type Flags struct { // OutputDir is where the generated code is to be written to. OutputDir string @@ -65,15 +65,15 @@ func (f *Flags) AddTo(flagset *pflag.FlagSet) { // https://github.com/kcp-dev/code-generator/issues/4 func ValidateFlags(f Flags) error { if f.InputDir == "" { - return errors.New("input path to API definition is required.") + return errors.New("input path to API definition is required") } if f.ClientsetAPIPath == "" { - return errors.New("specifying client API path is required currently.") + return errors.New("specifying client API path is required currently") } if len(f.GroupVersions) == 0 { - return errors.New("list of group versions for which the clients are to be generated is required.") + return errors.New("list of group versions for which the clients are to be generated is required") } return nil diff --git a/pkg/flag/flags_test.go b/pkg/flag/flags_test.go index 6617851e..25ab3a97 100644 --- a/pkg/flag/flags_test.go +++ b/pkg/flag/flags_test.go @@ -23,7 +23,7 @@ import ( . "github.com/onsi/gomega" ) -// TODO: Rewrite into generic Go Testing format +// TODO: Rewrite into generic Go Testing format. func TestMetadata(t *testing.T) { RegisterFailHandler(Fail) RunSpecs(t, "Test flags suite") @@ -47,19 +47,19 @@ var _ = Describe("Test flag inputs", func() { It("verify input path error", func() { f.InputDir = "" err := ValidateFlags(f) - Expect(err.Error()).To(ContainSubstring("input path to API definition is required.")) + Expect(err.Error()).To(ContainSubstring("input path to API definition is required")) }) It("verify clientsetAPI path", func() { f.ClientsetAPIPath = "" err := ValidateFlags(f) - Expect(err.Error()).To(ContainSubstring("specifying client API path is required currently.")) + Expect(err.Error()).To(ContainSubstring("specifying client API path is required currently")) }) It("verify group version list", func() { f.GroupVersions = []string{} err := ValidateFlags(f) - Expect(err.Error()).To(ContainSubstring("list of group versions for which the clients are to be generated is required.")) + Expect(err.Error()).To(ContainSubstring("list of group versions for which the clients are to be generated is required")) }) }) diff --git a/pkg/generators/informergen/informergen.go b/pkg/generators/informergen/informergen.go index 1f288c92..f8d3a855 100644 --- a/pkg/generators/informergen/informergen.go +++ b/pkg/generators/informergen/informergen.go @@ -109,7 +109,7 @@ func (g Generator) Generate(ctx *genall.GenerationContext) error { logger := klog.Background() - var onlyGroups []parser.Group + onlyGroups := make([]parser.Group, 0, len(groupVersionKinds)) for group := range groupVersionKinds { onlyGroups = append(onlyGroups, group) } diff --git a/pkg/parser/markers.go b/pkg/parser/markers.go index 19be38b8..97b394d7 100644 --- a/pkg/parser/markers.go +++ b/pkg/parser/markers.go @@ -100,7 +100,7 @@ func IsNamespaced(info *markers.TypeInfo) bool { return !IsClusterScoped(info) } -// SupportedVerbs determines which verbs the type supports +// SupportedVerbs determines which verbs the type supports. func SupportedVerbs(info *markers.TypeInfo) (sets.Set[string], error) { if info.Markers.Get(NoVerbsMarker.Name) != nil { return sets.New[string](), nil @@ -146,7 +146,7 @@ func ClientExtensions(info *markers.TypeInfo) []Extension { if !ok || values == nil { return nil } - var extensions []Extension + extensions := make([]Extension, 0, len(values)) for _, item := range values { extension, ok := item.(extension) if !ok { diff --git a/pkg/util/util.go b/pkg/util/util.go index b93277ea..d5f5bd99 100644 --- a/pkg/util/util.go +++ b/pkg/util/util.go @@ -34,7 +34,7 @@ func LowerFirst(s string) string { return strings.ToLower(string(s[0])) + s[1:] } -// UpperFirst sets the first alphabet to upperCase/ +// UpperFirst sets the first alphabet to upperCase. func UpperFirst(s string) string { return strings.ToUpper(string(s[0])) + s[1:] }