Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: rename options dropping suffix #312

Merged
merged 1 commit into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/artifact/artifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
)

// NewArtifactCmd return the artifact command.
func NewArtifactCmd(ctx context.Context, opt *commonoptions.CommonOptions) *cobra.Command {
func NewArtifactCmd(ctx context.Context, opt *commonoptions.Common) *cobra.Command {
cmd := &cobra.Command{
Use: "artifact",
DisableFlagsInUseLine: true,
Expand Down
18 changes: 10 additions & 8 deletions cmd/artifact/follow/follow.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ Example - Install and follow "cloudtrail" plugins using a fully qualified refere
)

type artifactFollowOptions struct {
*options.CommonOptions
*options.RegistryOptions
*options.Common
*options.Registry
rulesfilesDir string
pluginsDir string
tmpDir string
Expand All @@ -94,12 +94,14 @@ type artifactFollowOptions struct {
}

// NewArtifactFollowCmd returns the artifact follow command.
func NewArtifactFollowCmd(ctx context.Context, opt *options.CommonOptions) *cobra.Command {
//
//nolint:gocyclo // unknown reason for cyclomatic complexity
func NewArtifactFollowCmd(ctx context.Context, opt *options.Common) *cobra.Command {
o := artifactFollowOptions{
CommonOptions: opt,
RegistryOptions: &options.RegistryOptions{},
closeChan: make(chan bool),
versions: config.FalcoVersions{},
Common: opt,
Registry: &options.Registry{},
closeChan: make(chan bool),
versions: config.FalcoVersions{},
}

cmd := &cobra.Command{
Expand Down Expand Up @@ -220,7 +222,7 @@ func NewArtifactFollowCmd(ctx context.Context, opt *options.CommonOptions) *cobr
},
}

o.RegistryOptions.AddFlags(cmd)
o.Registry.AddFlags(cmd)
cmd.Flags().DurationVarP(&o.every, "every", "e", config.FollowResync, "Time interval how often it checks for a new version of the "+
"artifact. Cannot be used together with 'cron' option.")
cmd.Flags().StringVar(&o.cron, "cron", "", "Cron-like string to specify interval how often it checks for a new version of the artifact."+
Expand Down
12 changes: 6 additions & 6 deletions cmd/artifact/info/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ import (
)

type artifactInfoOptions struct {
*options.CommonOptions
*options.RegistryOptions
*options.Common
*options.Registry
}

// NewArtifactInfoCmd returns the artifact info command.
func NewArtifactInfoCmd(ctx context.Context, opt *options.CommonOptions) *cobra.Command {
func NewArtifactInfoCmd(ctx context.Context, opt *options.Common) *cobra.Command {
o := artifactInfoOptions{
CommonOptions: opt,
RegistryOptions: &options.RegistryOptions{},
Common: opt,
Registry: &options.Registry{},
}

cmd := &cobra.Command{
Expand All @@ -53,7 +53,7 @@ func NewArtifactInfoCmd(ctx context.Context, opt *options.CommonOptions) *cobra.
},
}

o.RegistryOptions.AddFlags(cmd)
o.Registry.AddFlags(cmd)

return cmd
}
Expand Down
12 changes: 6 additions & 6 deletions cmd/artifact/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ Example - Install "cloudtrail" plugins using a fully qualified reference:
)

type artifactInstallOptions struct {
*options.CommonOptions
*options.RegistryOptions
*options.Common
*options.Registry
rulesfilesDir string
pluginsDir string
allowedTypes oci.ArtifactTypeSlice
Expand All @@ -79,10 +79,10 @@ type artifactInstallOptions struct {
}

// NewArtifactInstallCmd returns the artifact install command.
func NewArtifactInstallCmd(ctx context.Context, opt *options.CommonOptions) *cobra.Command {
func NewArtifactInstallCmd(ctx context.Context, opt *options.Common) *cobra.Command {
o := artifactInstallOptions{
CommonOptions: opt,
RegistryOptions: &options.RegistryOptions{},
Common: opt,
Registry: &options.Registry{},
}

cmd := &cobra.Command{
Expand Down Expand Up @@ -161,7 +161,7 @@ func NewArtifactInstallCmd(ctx context.Context, opt *options.CommonOptions) *cob
},
}

o.RegistryOptions.AddFlags(cmd)
o.Registry.AddFlags(cmd)
cmd.Flags().StringVarP(&o.rulesfilesDir, FlagRulesFilesDir, "", config.RulesfilesDir,
"directory where to install rules.")
cmd.Flags().StringVarP(&o.pluginsDir, FlagPluginsFilesDir, "", config.PluginsDir,
Expand Down
6 changes: 3 additions & 3 deletions cmd/artifact/list/artifact_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ import (
const CommandName = "list"

type artifactListOptions struct {
*options.CommonOptions
*options.Common
artifactType oci.ArtifactType
index string
}

// NewArtifactListCmd returns the artifact search command.
func NewArtifactListCmd(ctx context.Context, opt *options.CommonOptions) *cobra.Command {
func NewArtifactListCmd(ctx context.Context, opt *options.Common) *cobra.Command {
o := artifactListOptions{
CommonOptions: opt,
Common: opt,
}

cmd := &cobra.Command{
Expand Down
6 changes: 3 additions & 3 deletions cmd/artifact/search/artifact_search.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const (
)

type artifactSearchOptions struct {
*options.CommonOptions
*options.Common
minScore float64
artifactType oci.ArtifactType
}
Expand All @@ -46,9 +46,9 @@ func (o *artifactSearchOptions) Validate() error {
}

// NewArtifactSearchCmd returns the artifact search command.
func NewArtifactSearchCmd(ctx context.Context, opt *options.CommonOptions) *cobra.Command {
func NewArtifactSearchCmd(ctx context.Context, opt *options.Common) *cobra.Command {
o := artifactSearchOptions{
CommonOptions: opt,
Common: opt,
}

cmd := &cobra.Command{
Expand Down
2 changes: 1 addition & 1 deletion cmd/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ var tests = []testCase{

func run(t *testing.T, test *testCase) {
// Setup
c := New(context.Background(), &options.CommonOptions{})
c := New(context.Background(), &options.Common{})
o := bytes.NewBufferString("")
c.SetOut(o)
c.SetErr(o)
Expand Down
2 changes: 1 addition & 1 deletion cmd/cmd_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ var (
ctx = context.Background()
output = gbytes.NewBuffer()
rootCmd *cobra.Command
opt *commonoptions.CommonOptions
opt *commonoptions.Common
port int
orasRegistry *remote.Registry
configFile string
Expand Down
6 changes: 3 additions & 3 deletions cmd/index/add/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ import (

// IndexAddOptions contains the options for the index add command.
type IndexAddOptions struct {
*options.CommonOptions
*options.Common
}

// NewIndexAddCmd returns the index add command.
func NewIndexAddCmd(ctx context.Context, opt *options.CommonOptions) *cobra.Command {
func NewIndexAddCmd(ctx context.Context, opt *options.Common) *cobra.Command {
o := IndexAddOptions{
CommonOptions: opt,
Common: opt,
}

cmd := &cobra.Command{
Expand Down
2 changes: 1 addition & 1 deletion cmd/index/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
)

// NewIndexCmd returns the index command.
func NewIndexCmd(ctx context.Context, opt *commonoptions.CommonOptions) *cobra.Command {
func NewIndexCmd(ctx context.Context, opt *commonoptions.Common) *cobra.Command {
cmd := &cobra.Command{
Use: "index",
DisableFlagsInUseLine: true,
Expand Down
6 changes: 3 additions & 3 deletions cmd/index/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ import (
)

type indexListOptions struct {
*options.CommonOptions
*options.Common
}

// NewIndexListCmd returns the index list command.
func NewIndexListCmd(_ context.Context, opt *options.CommonOptions) *cobra.Command {
func NewIndexListCmd(_ context.Context, opt *options.Common) *cobra.Command {
o := indexListOptions{
CommonOptions: opt,
Common: opt,
}

cmd := &cobra.Command{
Expand Down
6 changes: 3 additions & 3 deletions cmd/index/remove/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ import (
)

type indexRemoveOptions struct {
*options.CommonOptions
*options.Common
}

// NewIndexRemoveCmd returns the index remove command.
func NewIndexRemoveCmd(ctx context.Context, opt *options.CommonOptions) *cobra.Command {
func NewIndexRemoveCmd(ctx context.Context, opt *options.Common) *cobra.Command {
o := indexRemoveOptions{
CommonOptions: opt,
Common: opt,
}

cmd := &cobra.Command{
Expand Down
6 changes: 3 additions & 3 deletions cmd/index/update/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ import (
)

type indexUpdateOptions struct {
*options.CommonOptions
*options.Common
}

// NewIndexUpdateCmd returns the index update command.
func NewIndexUpdateCmd(ctx context.Context, opt *options.CommonOptions) *cobra.Command {
func NewIndexUpdateCmd(ctx context.Context, opt *options.Common) *cobra.Command {
o := indexUpdateOptions{
CommonOptions: opt,
Common: opt,
}

cmd := &cobra.Command{
Expand Down
2 changes: 1 addition & 1 deletion cmd/registry/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
)

// NewAuthCmd returns the registry command.
func NewAuthCmd(ctx context.Context, opt *commonoptions.CommonOptions) *cobra.Command {
func NewAuthCmd(ctx context.Context, opt *commonoptions.Common) *cobra.Command {
cmd := &cobra.Command{
Use: "auth",
DisableFlagsInUseLine: true,
Expand Down
6 changes: 3 additions & 3 deletions cmd/registry/auth/basic/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ import (
)

type loginOptions struct {
*options.CommonOptions
*options.Common
}

// NewBasicCmd returns the basic command.
func NewBasicCmd(ctx context.Context, opt *options.CommonOptions) *cobra.Command {
func NewBasicCmd(ctx context.Context, opt *options.Common) *cobra.Command {
o := loginOptions{
CommonOptions: opt,
Common: opt,
}

cmd := &cobra.Command{
Expand Down
6 changes: 3 additions & 3 deletions cmd/registry/auth/gcp/gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ Example

// RegistryGcpOptions contains the options for the registry gcp command.
type RegistryGcpOptions struct {
*options.CommonOptions
*options.Common
}

// NewGcpCmd returns the gcp command.
func NewGcpCmd(ctx context.Context, opt *options.CommonOptions) *cobra.Command {
func NewGcpCmd(ctx context.Context, opt *options.Common) *cobra.Command {
o := RegistryGcpOptions{
CommonOptions: opt,
Common: opt,
}

cmd := &cobra.Command{
Expand Down
6 changes: 3 additions & 3 deletions cmd/registry/auth/oauth/oauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ Example

// RegistryOauthOptions contains the options for the registry oauth command.
type RegistryOauthOptions struct {
*options.CommonOptions
*options.Common
Conf clientcredentials.Config
}

// NewOauthCmd returns the oauth command.
func NewOauthCmd(ctx context.Context, opt *options.CommonOptions) *cobra.Command {
func NewOauthCmd(ctx context.Context, opt *options.Common) *cobra.Command {
o := RegistryOauthOptions{
CommonOptions: opt,
Common: opt,
}

cmd := &cobra.Command{
Expand Down
22 changes: 11 additions & 11 deletions cmd/registry/pull/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,22 @@ Example - Pull artifact "myrulesfile":
)

type pullOptions struct {
*options.CommonOptions
*options.ArtifactOptions
*options.RegistryOptions
*options.Common
*options.Artifact
*options.Registry
destDir string
}

func (o *pullOptions) Validate() error {
return o.ArtifactOptions.Validate()
return o.Artifact.Validate()
}

// NewPullCmd returns the pull command.
func NewPullCmd(ctx context.Context, opt *options.CommonOptions) *cobra.Command {
func NewPullCmd(ctx context.Context, opt *options.Common) *cobra.Command {
o := pullOptions{
CommonOptions: opt,
ArtifactOptions: &options.ArtifactOptions{},
RegistryOptions: &options.RegistryOptions{},
Common: opt,
Artifact: &options.Artifact{},
Registry: &options.Registry{},
}

cmd := &cobra.Command{
Expand Down Expand Up @@ -98,8 +98,8 @@ func NewPullCmd(ctx context.Context, opt *options.CommonOptions) *cobra.Command
},
}

o.RegistryOptions.AddFlags(cmd)
output.ExitOnErr(o.Printer, o.ArtifactOptions.AddFlags(cmd))
o.Registry.AddFlags(cmd)
output.ExitOnErr(o.Printer, o.Artifact.AddFlags(cmd))
cmd.Flags().StringVarP(&o.destDir, "dest-dir", "o", "", "destination dir where to save the artifacts(default: current directory)")
return cmd
}
Expand Down Expand Up @@ -132,7 +132,7 @@ func (o *pullOptions) RunPull(ctx context.Context, args []string) error {
}

os, arch := runtime.GOOS, runtime.GOARCH
if len(o.ArtifactOptions.Platforms) > 0 {
if len(o.Artifact.Platforms) > 0 {
os, arch = o.OSArch(0)
}

Expand Down
Loading