From df0b601459274569ac74fbdb9d17c65e678b6c47 Mon Sep 17 00:00:00 2001 From: Christopher Fry Date: Fri, 4 Nov 2022 15:53:33 +0000 Subject: [PATCH] add validations to `kpt alpha rpkg init` command --- commands/alpha/rpkg/clone/command.go | 2 +- commands/alpha/rpkg/copy/command.go | 2 +- commands/alpha/rpkg/init/command.go | 12 ++++++++++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/commands/alpha/rpkg/clone/command.go b/commands/alpha/rpkg/clone/command.go index 97504d4dde..969f40e814 100644 --- a/commands/alpha/rpkg/clone/command.go +++ b/commands/alpha/rpkg/clone/command.go @@ -113,7 +113,7 @@ func (r *runner) preRunE(cmd *cobra.Command, args []string) error { } if r.workspace == "" { - return errors.E(op, fmt.Errorf("--workspace is required to specify downstream workspaceName")) + return errors.E(op, fmt.Errorf("--workspace is required to specify downstream workspace name")) } source := args[0] diff --git a/commands/alpha/rpkg/copy/command.go b/commands/alpha/rpkg/copy/command.go index d928f5025c..ee5f90c311 100644 --- a/commands/alpha/rpkg/copy/command.go +++ b/commands/alpha/rpkg/copy/command.go @@ -124,7 +124,7 @@ func (r *runner) getPackageRevisionSpec() (*porchapi.PackageRevisionSpec, error) } if r.workspace == "" { - return nil, fmt.Errorf("--workspace is required to specify downstream workspaceName") + return nil, fmt.Errorf("--workspace is required to specify workspace name") } spec := &porchapi.PackageRevisionSpec{ diff --git a/commands/alpha/rpkg/init/command.go b/commands/alpha/rpkg/init/command.go index ab81b180c2..158785e597 100644 --- a/commands/alpha/rpkg/init/command.go +++ b/commands/alpha/rpkg/init/command.go @@ -56,8 +56,8 @@ func newRunner(ctx context.Context, rcg *genericclioptions.ConfigFlags) *runner c.Flags().StringVar(&r.Description, "description", "sample description", "short description of the package.") c.Flags().StringSliceVar(&r.Keywords, "keywords", []string{}, "list of keywords for the package.") c.Flags().StringVar(&r.Site, "site", "", "link to page with information about the package.") - c.Flags().StringVar(&r.repository, "repository", "", "Repository to which package will be cloned (downstream repository).") - c.Flags().StringVar(&r.workspace, "workspace", "", "Workspace name of the downstream package.") + c.Flags().StringVar(&r.repository, "repository", "", "Repository to which package will be created.") + c.Flags().StringVar(&r.workspace, "workspace", "", "Workspace name of the package.") return r } @@ -90,6 +90,14 @@ func (r *runner) preRunE(cmd *cobra.Command, args []string) error { return errors.E(op, "PACKAGE_NAME is a required positional argument") } + if r.repository == "" { + return errors.E(op, fmt.Errorf("--repository is required to specify target repository")) + } + + if r.workspace == "" { + return errors.E(op, fmt.Errorf("--workspace is required to specify workspace name")) + } + r.name = args[0] pkgExists, err := util.PackageAlreadyExists(r.ctx, r.client, r.repository, r.name, *r.cfg.Namespace) if err != nil {