Skip to content

Commit

Permalink
refactor: rename options dropping suffix
Browse files Browse the repository at this point in the history
Signed-off-by: Lorenzo Susini <[email protected]>
  • Loading branch information
loresuso committed Aug 3, 2023
1 parent 3c017ed commit 0bb847f
Show file tree
Hide file tree
Showing 26 changed files with 101 additions and 101 deletions.
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
16 changes: 8 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,12 @@ type artifactFollowOptions struct {
}

// NewArtifactFollowCmd returns the artifact follow command.
func NewArtifactFollowCmd(ctx context.Context, opt *options.CommonOptions) *cobra.Command {
func NewArtifactFollowCmd(ctx context.Context, opt *options.Common) *cobra.Command {

Check failure on line 97 in cmd/artifact/follow/follow.go

View workflow job for this annotation

GitHub Actions / Lint golang files

cyclomatic complexity 35 of func `NewArtifactFollowCmd` is high (> 30) (gocyclo)
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 +220,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
20 changes: 10 additions & 10 deletions cmd/registry/push/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,21 @@ Example - Push artifact "myrulesfile.tar.gz" of type "rulesfile" with multiple d
)

type pushOptions struct {
*options.CommonOptions
*options.ArtifactOptions
*options.RegistryOptions
*options.Common
*options.Artifact
*options.Registry
}

func (o pushOptions) validate() error {
return o.ArtifactOptions.Validate()
return o.Artifact.Validate()
}

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

cmd := &cobra.Command{
Expand Down Expand Up @@ -110,8 +110,8 @@ func NewPushCmd(ctx context.Context, opt *options.CommonOptions) *cobra.Command
return o.runPush(ctx, args)
},
}
o.RegistryOptions.AddFlags(cmd)
output.ExitOnErr(o.Printer, o.ArtifactOptions.AddFlags(cmd))
o.Registry.AddFlags(cmd)
output.ExitOnErr(o.Printer, o.Artifact.AddFlags(cmd))

return cmd
}
Expand Down
Loading

0 comments on commit 0bb847f

Please sign in to comment.