diff --git a/cmd/operator-sdk/cleanup/packagemanifests/packagemanifests.go b/cmd/operator-sdk/cleanup/packagemanifests/packagemanifests.go index 30a45b3c404..80dc1fe22fe 100644 --- a/cmd/operator-sdk/cleanup/packagemanifests/packagemanifests.go +++ b/cmd/operator-sdk/cleanup/packagemanifests/packagemanifests.go @@ -36,22 +36,11 @@ func NewCmd() *cobra.Command { Long: `'cleanup packagemanifests' destroys an Operator deployed with OLM using the 'run packagemanifests' command. The command's argument must be set to a valid package manifests root directory, ex. '/packagemanifests'.`, + PreRunE: func(cmd *cobra.Command, args []string) error { + return c.validate(args) + }, RunE: func(cmd *cobra.Command, args []string) error { - if len(args) > 0 { - if len(args) > 1 { - return fmt.Errorf("exactly one argument is required") - } - c.ManifestsDir = args[0] - } else { - c.ManifestsDir = "packagemanifests" - } - - log.Infof("Cleaning up operator in directory %s", c.ManifestsDir) - - if err := c.Cleanup(); err != nil { - log.Fatalf("Failed to clean up operator: %v", err) - } - return nil + return c.run() }, } @@ -59,3 +48,24 @@ ex. '/packagemanifests'.`, return cmd } + +func (c *packagemanifestsCmd) validate(args []string) error { + if len(args) > 0 { + if len(args) > 1 { + return fmt.Errorf("exactly one argument is required") + } + c.ManifestsDir = args[0] + } else { + c.ManifestsDir = "packagemanifests" + } + return nil +} + +func (c *packagemanifestsCmd) run() error { + log.Infof("Cleaning up operator in directory %s", c.ManifestsDir) + + if err := c.Cleanup(); err != nil { + log.Fatalf("Failed to clean up operator: %v", err) + } + return nil +}