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

Bug 1881527: fix(opm): properly deprecate export flag '-o' #485

Merged
merged 1 commit into from Oct 22, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 28 additions & 1 deletion cmd/opm/index/export.go
@@ -1,6 +1,8 @@
package index

import (
"fmt"

"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"k8s.io/kubectl/pkg/util/templates"
Expand Down Expand Up @@ -33,7 +35,6 @@ func newIndexExportCmd() *cobra.Command {

RunE: runIndexExportCmdFunc,
}

indexCmd.Flags().Bool("debug", false, "enable debug logging")
indexCmd.Flags().StringP("index", "i", "", "index to get package from")
if err := indexCmd.MarkFlagRequired("index"); err != nil {
Expand All @@ -46,6 +47,12 @@ func newIndexExportCmd() *cobra.Command {
logrus.Panic(err.Error())
}

// Create hidden option so we can provide deprecated shorthand
indexCmd.Flags().StringSliceP("xpackage", "o", nil, "deprecated, please use --package option instead")
if err := indexCmd.Flags().MarkHidden("xpackage"); err != nil {
logrus.Panic(err.Error())
}

return indexCmd

}
Expand All @@ -56,10 +63,30 @@ func runIndexExportCmdFunc(cmd *cobra.Command, args []string) error {
return err
}

pkgFlag := cmd.Flag("package")
if pkgFlag == nil {
return fmt.Errorf("unable to get the package flag")
}

xPkgFlag := cmd.Flag("xpackage")
if xPkgFlag == nil {
return fmt.Errorf("unable to get the package flag for deprecated shorthand '-o'")
}

if xPkgFlag.Changed && pkgFlag.Changed {
return fmt.Errorf("cannot simultaneously set '-p' and '-o' flags, remove '-o'")
}

packages, err := cmd.Flags().GetStringSlice("package")
if err != nil {
return err
}
if xPkgFlag.Changed {
// Use the deprecated shorthand
if packages, err = cmd.Flags().GetStringSlice("xpackage"); err != nil {
return err
}
}

downloadPath, err := cmd.Flags().GetString("download-folder")
if err != nil {
Expand Down