Skip to content

Commit

Permalink
fix: update opm commands to specifc if they don't take args
Browse files Browse the repository at this point in the history
Signed-off-by: Tyler Slaton <tyslaton@redhat.com>
  • Loading branch information
Tyler Slaton committed Sep 22, 2021
1 parent 195bc03 commit 01f2071
Show file tree
Hide file tree
Showing 21 changed files with 52 additions and 31 deletions.
3 changes: 2 additions & 1 deletion cmd/opm/alpha/bundle/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func newBundleBuildCmd() *cobra.Command {
* All manifests yaml must be in the same directory.
`,
RunE: buildFunc,
Args: cobra.NoArgs,
}

bundleBuildCmd.Flags().StringVarP(&buildDir, "directory", "d", "",
Expand Down Expand Up @@ -79,7 +80,7 @@ func newBundleBuildCmd() *cobra.Command {
return bundleBuildCmd
}

func buildFunc(cmd *cobra.Command, args []string) error {
func buildFunc(cmd *cobra.Command, _ []string) error {
return bundle.BuildFunc(
buildDir,
outputDir,
Expand Down
1 change: 1 addition & 0 deletions cmd/opm/alpha/bundle/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ func NewCmd() *cobra.Command {
Use: "bundle",
Short: "Operator bundle commands",
Long: `Generate operator bundle metadata and build bundle image.`,
Args: cobra.NoArgs,
}

runCmd.AddCommand(newBundleGenerateCmd())
Expand Down
5 changes: 3 additions & 2 deletions cmd/opm/alpha/bundle/extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ var extractCmd = &cobra.Command{
Short: "Extracts the data in a bundle directory via ConfigMap",
Long: "Extract takes as input a directory containing manifests and writes the per file contents to a ConfipMap",

PreRunE: func(cmd *cobra.Command, args []string) error {
PreRunE: func(cmd *cobra.Command, _ []string) error {
if debug, _ := cmd.Flags().GetBool("debug"); debug {
logrus.SetLevel(logrus.DebugLevel)
}
return nil
},

RunE: runExtractCmd,
Args: cobra.NoArgs,
}

func init() {
Expand All @@ -35,7 +36,7 @@ func init() {
extractCmd.MarkPersistentFlagRequired("configmapname")
}

func runExtractCmd(cmd *cobra.Command, args []string) error {
func runExtractCmd(cmd *cobra.Command, _ []string) error {
manifestsDir, err := cmd.Flags().GetString("manifestsdir")
if err != nil {
return err
Expand Down
3 changes: 2 additions & 1 deletion cmd/opm/alpha/bundle/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func newBundleGenerateCmd() *cobra.Command {
* All manifests yaml must be in the same directory.
`,
RunE: generateFunc,
Args: cobra.NoArgs,
}

bundleGenerateCmd.Flags().StringVarP(&buildDir, "directory", "d", "",
Expand All @@ -48,7 +49,7 @@ func newBundleGenerateCmd() *cobra.Command {
return bundleGenerateCmd
}

func generateFunc(cmd *cobra.Command, args []string) error {
func generateFunc(cmd *cobra.Command, _ []string) error {
return bundle.GenerateFunc(
buildDir,
outputDir,
Expand Down
3 changes: 2 additions & 1 deletion cmd/opm/alpha/bundle/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Optional validators. These validators are disabled by default and can be enabled
See https://olm.operatorframework.io/docs/tasks/validate-package/#validation for more info.`,
Example: `$ opm alpha bundle validate --tag quay.io/test/test-operator:latest --image-builder docker`,
RunE: validateFunc,
Args: cobra.NoArgs,
}

bundleValidateCmd.Flags().StringVarP(&tag, "tag", "t", "",
Expand All @@ -52,7 +53,7 @@ See https://olm.operatorframework.io/docs/tasks/validate-package/#validation for
return bundleValidateCmd
}

func validateFunc(cmd *cobra.Command, args []string) error {
func validateFunc(cmd *cobra.Command, _ []string) error {
logger := log.WithFields(log.Fields{"container-tool": containerTool})
log.SetLevel(log.DebugLevel)

Expand Down
1 change: 1 addition & 0 deletions cmd/opm/alpha/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ func NewCmd() *cobra.Command {
Hidden: true,
Use: "alpha",
Short: "Run an alpha subcommand",
Args: cobra.NoArgs,
}

runCmd.AddCommand(
Expand Down
5 changes: 3 additions & 2 deletions cmd/opm/index/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,14 @@ func addIndexAddCmd(parent *cobra.Command) {
Use: "add",
Short: "Add operator bundles to an index.",
Long: addLong,
PreRunE: func(cmd *cobra.Command, args []string) error {
PreRunE: func(cmd *cobra.Command, _ []string) error {
if debug, _ := cmd.Flags().GetBool("debug"); debug {
logrus.SetLevel(logrus.DebugLevel)
}
return nil
},
RunE: runIndexAddCmdFunc,
Args: cobra.NoArgs,
}

indexCmd.Flags().Bool("debug", false, "enable debug logging")
Expand Down Expand Up @@ -89,7 +90,7 @@ func addIndexAddCmd(parent *cobra.Command) {

}

func runIndexAddCmdFunc(cmd *cobra.Command, args []string) error {
func runIndexAddCmdFunc(cmd *cobra.Command, _ []string) error {
generate, err := cmd.Flags().GetBool("generate")
if err != nil {
return err
Expand Down
5 changes: 3 additions & 2 deletions cmd/opm/index/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,19 @@ func AddCommand(parent *cobra.Command) {
` + sqlite.DeprecationMessage,

PreRunE: func(cmd *cobra.Command, args []string) error {
PreRunE: func(cmd *cobra.Command, _ []string) error {
if debug, _ := cmd.Flags().GetBool("debug"); debug {
logrus.SetLevel(logrus.DebugLevel)
}
return nil
},
PersistentPreRun: func(cmd *cobra.Command, args []string) {
PersistentPreRun: func(cmd *cobra.Command, _ []string) {
sqlite.LogSqliteDeprecation()
if skipTLS, err := cmd.Flags().GetBool("skip-tls"); err == nil && skipTLS {
logrus.Warn("--skip-tls flag is set: this mode is insecure and meant for development purposes only.")
}
},
Args: cobra.NoArgs,
}

parent.AddCommand(cmd)
Expand Down
5 changes: 3 additions & 2 deletions cmd/opm/index/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ func newIndexDeleteCmd() *cobra.Command {
` + sqlite.DeprecationMessage,

PreRunE: func(cmd *cobra.Command, args []string) error {
PreRunE: func(cmd *cobra.Command, _ []string) error {
if debug, _ := cmd.Flags().GetBool("debug"); debug {
logrus.SetLevel(logrus.DebugLevel)
}
return nil
},

RunE: runIndexDeleteCmdFunc,
Args: cobra.NoArgs,
}

indexCmd.Flags().Bool("debug", false, "enable debug logging")
Expand Down Expand Up @@ -53,7 +54,7 @@ func newIndexDeleteCmd() *cobra.Command {

}

func runIndexDeleteCmdFunc(cmd *cobra.Command, args []string) error {
func runIndexDeleteCmdFunc(cmd *cobra.Command, _ []string) error {
generate, err := cmd.Flags().GetBool("generate")
if err != nil {
return err
Expand Down
5 changes: 3 additions & 2 deletions cmd/opm/index/deprecatetruncate.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,14 @@ func newIndexDeprecateTruncateCmd() *cobra.Command {
Use: "deprecatetruncate",
Short: "Deprecate and truncate operator bundles from an index.",
Long: deprecateLong,
PreRunE: func(cmd *cobra.Command, args []string) error {
PreRunE: func(cmd *cobra.Command, _ []string) error {
if debug, _ := cmd.Flags().GetBool("debug"); debug {
logrus.SetLevel(logrus.DebugLevel)
}
return nil
},
RunE: runIndexDeprecateTruncateCmdFunc,
Args: cobra.NoArgs,
}

indexCmd.Flags().Bool("debug", false, "enable debug logging")
Expand All @@ -68,7 +69,7 @@ func newIndexDeprecateTruncateCmd() *cobra.Command {
return indexCmd
}

func runIndexDeprecateTruncateCmdFunc(cmd *cobra.Command, args []string) error {
func runIndexDeprecateTruncateCmdFunc(cmd *cobra.Command, _ []string) error {
generate, err := cmd.Flags().GetBool("generate")
if err != nil {
return err
Expand Down
5 changes: 3 additions & 2 deletions cmd/opm/index/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@ func newIndexExportCmd() *cobra.Command {
Short: "Export an operator from an index into the appregistry format",
Long: exportLong,

PreRunE: func(cmd *cobra.Command, args []string) error {
PreRunE: func(cmd *cobra.Command, _ []string) error {
if debug, _ := cmd.Flags().GetBool("debug"); debug {
logrus.SetLevel(logrus.DebugLevel)
}
return nil
},

RunE: runIndexExportCmdFunc,
Args: cobra.NoArgs,
}
indexCmd.Flags().Bool("debug", false, "enable debug logging")
indexCmd.Flags().StringP("index", "i", "", "index to get package from")
Expand All @@ -58,7 +59,7 @@ func newIndexExportCmd() *cobra.Command {

}

func runIndexExportCmdFunc(cmd *cobra.Command, args []string) error {
func runIndexExportCmdFunc(cmd *cobra.Command, _ []string) error {
index, err := cmd.Flags().GetString("index")
if err != nil {
return err
Expand Down
5 changes: 3 additions & 2 deletions cmd/opm/index/prune.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ func newIndexPruneCmd() *cobra.Command {
` + sqlite.DeprecationMessage,

PreRunE: func(cmd *cobra.Command, args []string) error {
PreRunE: func(cmd *cobra.Command, _ []string) error {
if debug, _ := cmd.Flags().GetBool("debug"); debug {
logrus.SetLevel(logrus.DebugLevel)
}
return nil
},

RunE: runIndexPruneCmdFunc,
Args: cobra.NoArgs,
}

indexCmd.Flags().Bool("debug", false, "enable debug logging")
Expand All @@ -53,7 +54,7 @@ func newIndexPruneCmd() *cobra.Command {

}

func runIndexPruneCmdFunc(cmd *cobra.Command, args []string) error {
func runIndexPruneCmdFunc(cmd *cobra.Command, _ []string) error {
generate, err := cmd.Flags().GetBool("generate")
if err != nil {
return err
Expand Down
5 changes: 3 additions & 2 deletions cmd/opm/index/prunestranded.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ func newIndexPruneStrandedCmd() *cobra.Command {
` + sqlite.DeprecationMessage,

PreRunE: func(cmd *cobra.Command, args []string) error {
PreRunE: func(cmd *cobra.Command, _ []string) error {
if debug, _ := cmd.Flags().GetBool("debug"); debug {
logrus.SetLevel(logrus.DebugLevel)
}
return nil
},

RunE: runIndexPruneStrandedCmdFunc,
Args: cobra.NoArgs,
}

indexCmd.Flags().Bool("debug", false, "enable debug logging")
Expand All @@ -48,7 +49,7 @@ func newIndexPruneStrandedCmd() *cobra.Command {

}

func runIndexPruneStrandedCmdFunc(cmd *cobra.Command, args []string) error {
func runIndexPruneStrandedCmdFunc(cmd *cobra.Command, _ []string) error {
generate, err := cmd.Flags().GetBool("generate")
if err != nil {
return err
Expand Down
5 changes: 3 additions & 2 deletions cmd/opm/registry/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ func newRegistryAddCmd() *cobra.Command {
` + sqlite.DeprecationMessage,

PreRunE: func(cmd *cobra.Command, args []string) error {
PreRunE: func(cmd *cobra.Command, _ []string) error {
if debug, _ := cmd.Flags().GetBool("debug"); debug {
logrus.SetLevel(logrus.DebugLevel)
}
return nil
},

RunE: addFunc,
Args: cobra.NoArgs,
}

rootCmd.Flags().Bool("debug", false, "enable debug logging")
Expand All @@ -43,7 +44,7 @@ func newRegistryAddCmd() *cobra.Command {
return rootCmd
}

func addFunc(cmd *cobra.Command, args []string) error {
func addFunc(cmd *cobra.Command, _ []string) error {
permissive, err := cmd.Flags().GetBool("permissive")
if err != nil {
return err
Expand Down
3 changes: 2 additions & 1 deletion cmd/opm/registry/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ func NewOpmRegistryCmd() *cobra.Command {
PersistentPreRun: func(_ *cobra.Command, _ []string) {
sqlite.LogSqliteDeprecation()
},
PreRunE: func(cmd *cobra.Command, args []string) error {
PreRunE: func(cmd *cobra.Command, _ []string) error {
if debug, _ := cmd.Flags().GetBool("debug"); debug {
logrus.SetLevel(logrus.DebugLevel)
}
return nil
},
Args: cobra.NoArgs,
}

rootCmd.AddCommand(newRegistryServeCmd())
Expand Down
1 change: 1 addition & 0 deletions cmd/opm/registry/mirror.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func MirrorCmd() *cobra.Command {
}
return nil
},
Args: cobra.ExactArgs(2),
}
flags := cmd.Flags()

Expand Down
5 changes: 3 additions & 2 deletions cmd/opm/registry/prune.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ func newRegistryPruneCmd() *cobra.Command {
` + sqlite.DeprecationMessage,

PreRunE: func(cmd *cobra.Command, args []string) error {
PreRunE: func(cmd *cobra.Command, _ []string) error {
if debug, _ := cmd.Flags().GetBool("debug"); debug {
logrus.SetLevel(logrus.DebugLevel)
}
return nil
},

RunE: runRegistryPruneCmdFunc,
Args: cobra.NoArgs,
}

rootCmd.Flags().Bool("debug", false, "enable debug logging")
Expand All @@ -37,7 +38,7 @@ func newRegistryPruneCmd() *cobra.Command {
return rootCmd
}

func runRegistryPruneCmdFunc(cmd *cobra.Command, args []string) error {
func runRegistryPruneCmdFunc(cmd *cobra.Command, _ []string) error {
fromFilename, err := cmd.Flags().GetString("database")
if err != nil {
return err
Expand Down
5 changes: 3 additions & 2 deletions cmd/opm/registry/prunestranded.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ func newRegistryPruneStrandedCmd() *cobra.Command {
` + sqlite.DeprecationMessage,

PreRunE: func(cmd *cobra.Command, args []string) error {
PreRunE: func(cmd *cobra.Command, _ []string) error {
if debug, _ := cmd.Flags().GetBool("debug"); debug {
logrus.SetLevel(logrus.DebugLevel)
}
return nil
},

RunE: runRegistryPruneStrandedCmdFunc,
Args: cobra.NoArgs,
}

rootCmd.Flags().Bool("debug", false, "enable debug logging")
Expand All @@ -32,7 +33,7 @@ func newRegistryPruneStrandedCmd() *cobra.Command {
return rootCmd
}

func runRegistryPruneStrandedCmdFunc(cmd *cobra.Command, args []string) error {
func runRegistryPruneStrandedCmdFunc(cmd *cobra.Command, _ []string) error {
fromFilename, err := cmd.Flags().GetString("database")
if err != nil {
return err
Expand Down
5 changes: 3 additions & 2 deletions cmd/opm/registry/rm.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ func newRegistryRmCmd() *cobra.Command {
` + sqlite.DeprecationMessage,

PreRunE: func(cmd *cobra.Command, args []string) error {
PreRunE: func(cmd *cobra.Command, _ []string) error {
if debug, _ := cmd.Flags().GetBool("debug"); debug {
logrus.SetLevel(logrus.DebugLevel)
}
return nil
},

RunE: rmFunc,
Args: cobra.NoArgs,
}

rootCmd.Flags().Bool("debug", false, "enable debug logging")
Expand All @@ -37,7 +38,7 @@ func newRegistryRmCmd() *cobra.Command {
return rootCmd
}

func rmFunc(cmd *cobra.Command, args []string) error {
func rmFunc(cmd *cobra.Command, _ []string) error {
fromFilename, err := cmd.Flags().GetString("database")
if err != nil {
return err
Expand Down
Loading

0 comments on commit 01f2071

Please sign in to comment.