Skip to content

Commit

Permalink
feat: centralize addition of flags to remove inconsistencies
Browse files Browse the repository at this point in the history
Signed-off-by: Dustin Scott <[email protected]>
  • Loading branch information
scottd018 committed Jul 3, 2024
1 parent 7e76115 commit 403fc85
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 14 deletions.
4 changes: 2 additions & 2 deletions internal/plugins/config/v1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"sigs.k8s.io/kubebuilder/v3/pkg/model/resource"
"sigs.k8s.io/kubebuilder/v3/pkg/plugin"

"github.com/nukleros/operator-builder/internal/plugins/workload"
workloadconfig "github.com/nukleros/operator-builder/internal/workload/v1/config"
"github.com/nukleros/operator-builder/internal/workload/v1/kinds"
)
Expand All @@ -26,8 +27,7 @@ type createAPISubcommand struct {
var _ plugin.CreateAPISubcommand = &createAPISubcommand{}

func (p *createAPISubcommand) BindFlags(fs *pflag.FlagSet) {
fs.StringVar(&p.workloadConfigPath, "workload-config", "", "path to workload config file")
fs.BoolVar(&p.enableOlm, "enable-olm", false, "enable support for OpenShift Lifecycle Manager")
workload.AddFlags(fs, &p.workloadConfigPath, &p.enableOlm)
}

func (p *createAPISubcommand) InjectConfig(c config.Config) error {
Expand Down
5 changes: 3 additions & 2 deletions internal/plugins/config/v1/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"sigs.k8s.io/kubebuilder/v3/pkg/machinery"
"sigs.k8s.io/kubebuilder/v3/pkg/plugin"

"github.com/nukleros/operator-builder/internal/plugins/workload"
workloadconfig "github.com/nukleros/operator-builder/internal/workload/v1/config"
)

Expand All @@ -24,9 +25,9 @@ type initSubcommand struct {
var _ plugin.InitSubcommand = &initSubcommand{}

func (p *initSubcommand) BindFlags(fs *pflag.FlagSet) {
fs.StringVar(&p.workloadConfigPath, "workload-config", "", "path to workload config file")
workload.AddFlags(fs, &p.workloadConfigPath, &p.enableOlm)

fs.StringVar(&p.controllerImage, "controller-image", "controller:latest", "controller image")
fs.BoolVar(&p.enableOlm, "enable-olm", false, "enable support for Operator Lifecycle Manager (OLM)")
}

func (p *initSubcommand) InjectConfig(c config.Config) error {
Expand Down
12 changes: 12 additions & 0 deletions internal/plugins/license/license.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright 2024 Nukleros
// SPDX-License-Identifier: MIT

package license

import "github.com/spf13/pflag"

// AddFlags adds a consistent set of license flags across plugin versions and commands.
func AddFlags(fs *pflag.FlagSet, projectLicensePath, sourceHeaderPath *string) {
fs.StringVar(projectLicensePath, "project-license", "", "path to project license file")
fs.StringVar(sourceHeaderPath, "source-header-license", "", "path to file with source code header license text")
}
4 changes: 2 additions & 2 deletions internal/plugins/license/v1/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"sigs.k8s.io/kubebuilder/v3/pkg/plugin"

"github.com/nukleros/operator-builder/internal/license"
licenseplugin "github.com/nukleros/operator-builder/internal/plugins/license"
)

var _ plugin.InitSubcommand = &initSubcommand{}
Expand All @@ -37,8 +38,7 @@ func (p *initSubcommand) UpdateMetadata(cliMeta plugin.CLIMetadata, subcmdMeta *
}

func (p *initSubcommand) BindFlags(fs *pflag.FlagSet) {
fs.StringVar(&p.projectLicensePath, "project-license", "", "path to project license file")
fs.StringVar(&p.sourceHeaderPath, "source-header-license", "", "path to file with source code header license text")
licenseplugin.AddFlags(fs, &p.projectLicensePath, &p.sourceHeaderPath)
}

func (p *initSubcommand) InjectConfig(c config.Config) {
Expand Down
4 changes: 2 additions & 2 deletions internal/plugins/license/v2/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"sigs.k8s.io/kubebuilder/v4/pkg/plugin"

"github.com/nukleros/operator-builder/internal/license"
licenseplugin "github.com/nukleros/operator-builder/internal/plugins/license"
)

var _ plugin.EditSubcommand = &editSubcommand{}
Expand All @@ -38,8 +39,7 @@ Features supported:
}

func (p *editSubcommand) BindFlags(fs *pflag.FlagSet) {
fs.StringVar(&p.projectLicensePath, "project-license", "", "path to project license file")
fs.StringVar(&p.sourceHeaderPath, "source-header-license", "", "path to file with source code header license text")
licenseplugin.AddFlags(fs, &p.projectLicensePath, &p.sourceHeaderPath)
}

func (p *editSubcommand) InjectConfig(c config.Config) error {
Expand Down
4 changes: 2 additions & 2 deletions internal/plugins/license/v2/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"sigs.k8s.io/kubebuilder/v4/pkg/plugin"

"github.com/nukleros/operator-builder/internal/license"
licenseplugin "github.com/nukleros/operator-builder/internal/plugins/license"
)

var _ plugin.InitSubcommand = &initSubcommand{}
Expand All @@ -37,8 +38,7 @@ func (p *initSubcommand) UpdateMetadata(cliMeta plugin.CLIMetadata, subcmdMeta *
}

func (p *initSubcommand) BindFlags(fs *pflag.FlagSet) {
fs.StringVar(&p.projectLicensePath, "project-license", "", "path to project license file")
fs.StringVar(&p.sourceHeaderPath, "source-header-license", "", "path to file with source code header license text")
licenseplugin.AddFlags(fs, &p.projectLicensePath, &p.sourceHeaderPath)
}

func (p *initSubcommand) InjectConfig(c config.Config) {
Expand Down
4 changes: 2 additions & 2 deletions internal/plugins/workload/v2/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
goplugin "sigs.k8s.io/kubebuilder/v4/pkg/plugins/golang"

"github.com/nukleros/operator-builder/internal/controllergen"
"github.com/nukleros/operator-builder/internal/plugins/workload"
"github.com/nukleros/operator-builder/internal/plugins/workload/v2/scaffolds"
"github.com/nukleros/operator-builder/internal/utils"
"github.com/nukleros/operator-builder/internal/workload/v1/commands/subcommand"
Expand Down Expand Up @@ -59,8 +60,7 @@ func (p *createAPISubcommand) UpdateMetadata(cliMeta plugin.CLIMetadata, subcmdM
}

func (p *createAPISubcommand) BindFlags(fs *pflag.FlagSet) {
fs.StringVar(&p.workloadConfigPath, "workload-config", "", "path to workload config file")
fs.BoolVar(&p.enableOlm, "enable-olm", false, "enable support for OpenShift Lifecycle Manager")
workload.AddFlags(fs, &p.workloadConfigPath, &p.enableOlm)

fs.BoolVar(&p.generateDeepCopy, "generate-deep-copy", true,
"if true, generate deep copy methods after scaffolding (equivalent of 'make generate')")
Expand Down
4 changes: 2 additions & 2 deletions internal/plugins/workload/v2/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"sigs.k8s.io/kubebuilder/v4/pkg/plugin"
"sigs.k8s.io/kubebuilder/v4/pkg/plugins/golang"

"github.com/nukleros/operator-builder/internal/plugins/workload"
"github.com/nukleros/operator-builder/internal/plugins/workload/v2/scaffolds"
"github.com/nukleros/operator-builder/internal/utils"
"github.com/nukleros/operator-builder/internal/workload/v1/commands/subcommand"
Expand Down Expand Up @@ -67,9 +68,8 @@ func (p *initSubcommand) UpdateMetadata(cliMeta plugin.CLIMetadata, subcmdMeta *
}

func (p *initSubcommand) BindFlags(fs *pflag.FlagSet) {
workload.AddFlags(fs, &p.workloadConfigPath, &p.enableOlm)
fs.StringVar(&p.controllerImage, "controller-image", "controller:latest", "controller image")
fs.StringVar(&p.workloadConfigPath, "workload-config", "", "path to workload config file")
fs.BoolVar(&p.enableOlm, "enable-olm", false, "enable support for OpenShift Lifecycle Manager")

fs.BoolVar(&p.skipGoVersionCheck, "skip-go-version-check",
false, "if specified, skip checking the Go version")
Expand Down
12 changes: 12 additions & 0 deletions internal/plugins/workload/workload.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright 2024 Nukleros
// SPDX-License-Identifier: MIT

package workload

import "github.com/spf13/pflag"

// AddFlags adds a consistent set of workload flags across plugin versions and commands.
func AddFlags(fs *pflag.FlagSet, workloadConfigPath *string, enableOlm *bool) {
fs.StringVar(workloadConfigPath, "workload-config", "", "path to workload config file")
fs.BoolVar(enableOlm, "enable-olm", false, "enable support for OpenShift Lifecycle Manager")
}

0 comments on commit 403fc85

Please sign in to comment.