Skip to content

Commit

Permalink
update(cmd): remove redundant configuration for error handling
Browse files Browse the repository at this point in the history
Furthemore, rewrite the tests for the root command using the ginkgo framework.

Signed-off-by: Aldo Lacuku <aldo@lacuku.eu>
  • Loading branch information
alacuku authored and poiana committed Oct 27, 2023
1 parent da90565 commit 49e73bb
Show file tree
Hide file tree
Showing 29 changed files with 172 additions and 261 deletions.
2 changes: 0 additions & 2 deletions cmd/artifact/artifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ func NewArtifactCmd(ctx context.Context, opt *commonoptions.Common) *cobra.Comma
DisableFlagsInUseLine: true,
Short: "Interact with Falco artifacts",
Long: "Interact with Falco artifacts",
SilenceErrors: true,
SilenceUsage: true,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
var indexes []config.Index
var indexCache *cache.Cache
Expand Down
8 changes: 3 additions & 5 deletions cmd/artifact/follow/follow.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,9 @@ func NewArtifactFollowCmd(ctx context.Context, opt *options.Common) *cobra.Comma
}

cmd := &cobra.Command{
Use: "follow [ref1 [ref2 ...]] [flags]",
Short: "Install a list of artifacts and continuously checks if there are updates",
Long: longFollow,
SilenceErrors: true,
SilenceUsage: true,
Use: "follow [ref1 [ref2 ...]] [flags]",
Short: "Install a list of artifacts and continuously checks if there are updates",
Long: longFollow,
PreRunE: func(cmd *cobra.Command, args []string) error {
// Override "every" flag with viper config if not set by user.
f := cmd.Flags().Lookup("every")
Expand Down
2 changes: 0 additions & 2 deletions cmd/artifact/info/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ func NewArtifactInfoCmd(ctx context.Context, opt *options.Common) *cobra.Command
Short: "Retrieve all available versions of a given artifact",
Long: "Retrieve all available versions of a given artifact",
Args: cobra.MinimumNArgs(1),
SilenceErrors: true,
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
return o.RunArtifactInfo(ctx, args)
},
Expand Down
2 changes: 0 additions & 2 deletions cmd/artifact/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@ func NewArtifactInstallCmd(ctx context.Context, opt *options.Common) *cobra.Comm
DisableFlagsInUseLine: true,
Short: "Install a list of artifacts",
Long: longInstall,
SilenceErrors: true,
SilenceUsage: true,
PreRunE: func(cmd *cobra.Command, args []string) error {
// Override "rulesfiles-dir" flag with viper config if not set by user.
f := cmd.Flags().Lookup(FlagRulesFilesDir)
Expand Down
2 changes: 0 additions & 2 deletions cmd/artifact/list/artifact_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ func NewArtifactListCmd(ctx context.Context, opt *options.Common) *cobra.Command
Short: "List all artifacts",
Long: "List all artifacts",
Aliases: []string{"ls"},
SilenceErrors: true,
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
return o.RunArtifactList(ctx, args)
},
Expand Down
2 changes: 0 additions & 2 deletions cmd/artifact/search/artifact_search.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ func NewArtifactSearchCmd(ctx context.Context, opt *options.Common) *cobra.Comma
Short: "Search an artifact by keywords",
Long: "Search an artifact by keywords",
Args: cobra.MinimumNArgs(1),
SilenceErrors: true,
SilenceUsage: true,
PreRunE: func(cmd *cobra.Command, args []string) error {
return o.Validate()
},
Expand Down
133 changes: 0 additions & 133 deletions cmd/cli_test.go

This file was deleted.

28 changes: 28 additions & 0 deletions cmd/cmd_suite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright (C) 2023 The Falco Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package cmd_test

import (
"testing"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

func TestCmd(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Cmd Suite")
}
2 changes: 0 additions & 2 deletions cmd/index/add/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ func NewIndexAddCmd(ctx context.Context, opt *options.Common) *cobra.Command {
Short: "Add an index to the local falcoctl configuration",
Long: "Add an index to the local falcoctl configuration. Indexes are used to perform search operations for artifacts",
Args: cobra.RangeArgs(2, 3),
SilenceErrors: true,
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
return o.RunIndexAdd(ctx, args)
},
Expand Down
2 changes: 0 additions & 2 deletions cmd/index/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ func NewIndexCmd(ctx context.Context, opt *commonoptions.Common) *cobra.Command
DisableFlagsInUseLine: true,
Short: "Interact with index",
Long: "Interact with index",
SilenceErrors: true,
SilenceUsage: true,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
opt.Initialize()
return config.Load(opt.ConfigFile)
Expand Down
2 changes: 0 additions & 2 deletions cmd/index/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ func NewIndexListCmd(_ context.Context, opt *options.Common) *cobra.Command {
Long: "List all the added indexes that were configured in falcoctl",
Args: cobra.ExactArgs(0),
Aliases: []string{"ls"},
SilenceErrors: true,
SilenceUsage: true,
RunE: func(cmd *cobra.Command, _ []string) error {
return o.RunIndexList()
},
Expand Down
2 changes: 0 additions & 2 deletions cmd/index/remove/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ func NewIndexRemoveCmd(ctx context.Context, opt *options.Common) *cobra.Command
Long: "Remove an index from the local falcoctl configuration",
Args: cobra.MinimumNArgs(1),
Aliases: []string{"rm"},
SilenceErrors: true,
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
return o.RunIndexRemove(ctx, args)
},
Expand Down
1 change: 0 additions & 1 deletion cmd/index/update/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ func NewIndexUpdateCmd(ctx context.Context, opt *options.Common) *cobra.Command
Short: "Update an existing index",
Long: "Update an existing index",
Args: cobra.MinimumNArgs(1),
SilenceErrors: true,
RunE: func(cmd *cobra.Command, args []string) error {
return o.RunIndexUpdate(ctx, args)
},
Expand Down
1 change: 0 additions & 1 deletion cmd/registry/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ func NewAuthCmd(ctx context.Context, opt *commonoptions.Common) *cobra.Command {
DisableFlagsInUseLine: true,
Short: "Handle authentication towards OCI registries",
Long: "Handle authentication towards OCI registries",
SilenceErrors: true,
}

cmd.AddCommand(basic.NewBasicCmd(ctx, opt))
Expand Down
2 changes: 0 additions & 2 deletions cmd/registry/auth/basic/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ func NewBasicCmd(ctx context.Context, opt *options.Common) *cobra.Command {
Short: "Login to an OCI registry",
Long: "Login to an OCI registry to push and pull artifacts",
Args: cobra.ExactArgs(1),
SilenceErrors: true,
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
return o.RunBasic(ctx, args)
},
Expand Down
2 changes: 0 additions & 2 deletions cmd/registry/auth/gcp/gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ func NewGcpCmd(ctx context.Context, opt *options.Common) *cobra.Command {
Short: "Register an Artifact Registry to log in using GCP Application Default credentials",
Long: longGcp,
Args: cobra.ExactArgs(1),
SilenceErrors: true,
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
return o.RunGcp(ctx, args)
},
Expand Down
2 changes: 0 additions & 2 deletions cmd/registry/auth/oauth/oauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ func NewOauthCmd(ctx context.Context, opt *options.Common) *cobra.Command {
Short: "Retrieve access and refresh tokens for OAuth2.0 client credentials flow authentication",
Long: longOauth,
Args: cobra.ExactArgs(1),
SilenceErrors: true,
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
return o.RunOAuth(ctx, args)
},
Expand Down
2 changes: 0 additions & 2 deletions cmd/registry/pull/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ func NewPullCmd(ctx context.Context, opt *options.Common) *cobra.Command {
Short: "Pull a Falco OCI artifact from remote registry",
Long: longPull,
Args: cobra.ExactArgs(1),
SilenceErrors: true,
SilenceUsage: true,
PreRunE: func(cmd *cobra.Command, args []string) error {
if err := o.Validate(); err != nil {
return err
Expand Down
2 changes: 0 additions & 2 deletions cmd/registry/push/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@ func NewPushCmd(ctx context.Context, opt *options.Common) *cobra.Command {
Short: "Push a Falco OCI artifact to remote registry",
Long: longPush,
Args: cobra.MinimumNArgs(2),
SilenceErrors: true,
SilenceUsage: true,
PreRunE: func(cmd *cobra.Command, args []string) error {
if err := o.validate(); err != nil {
return err
Expand Down
1 change: 0 additions & 1 deletion cmd/registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ func NewRegistryCmd(ctx context.Context, opt *commonoptions.Common) *cobra.Comma
DisableFlagsInUseLine: true,
Short: "Interact with OCI registries",
Long: "Interact with OCI registries",
SilenceErrors: true,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
// Initialize the options.
opt.Initialize()
Expand Down
2 changes: 2 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ func New(ctx context.Context, opt *options.Common) *cobra.Command {
Short: "The official CLI tool for working with Falco and its ecosystem components",
Long: longRootCmd,
SilenceErrors: true,
SilenceUsage: true,
TraverseChildren: true,
DisableAutoGenTag: true,
PersistentPreRun: func(cmd *cobra.Command, args []string) {
// Initialize the common options for all subcommands.
Expand Down

0 comments on commit 49e73bb

Please sign in to comment.