From 775c05423c939a0592a1969f2d4522525400d037 Mon Sep 17 00:00:00 2001 From: Maciej Szulik Date: Wed, 22 Aug 2018 14:04:47 +0200 Subject: [PATCH 1/2] UPSTREAM: 67698: Fix NameFromCommandArgs when passing command after -- --- .../k8s.io/kubernetes/pkg/kubectl/cmd/create/create.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/vendor/k8s.io/kubernetes/pkg/kubectl/cmd/create/create.go b/vendor/k8s.io/kubernetes/pkg/kubectl/cmd/create/create.go index e72b6d0796ab..3c492de31b59 100644 --- a/vendor/k8s.io/kubernetes/pkg/kubectl/cmd/create/create.go +++ b/vendor/k8s.io/kubernetes/pkg/kubectl/cmd/create/create.go @@ -327,8 +327,13 @@ func createAndRefresh(info *resource.Info) error { // NameFromCommandArgs is a utility function for commands that assume the first argument is a resource name func NameFromCommandArgs(cmd *cobra.Command, args []string) (string, error) { - if len(args) != 1 { - return "", cmdutil.UsageErrorf(cmd, "exactly one NAME is required, got %d", len(args)) + argsLen := cmd.ArgsLenAtDash() + // ArgsLenAtDash returns -1 when -- was not specified + if argsLen == -1 { + argsLen = len(args) + } + if argsLen != 1 { + return "", cmdutil.UsageErrorf(cmd, "exactly one NAME is required, got %d", argsLen) } return args[0], nil } From 7b24607e8831274702e17dd959823a76d34a930e Mon Sep 17 00:00:00 2001 From: Maciej Szulik Date: Wed, 22 Aug 2018 14:04:56 +0200 Subject: [PATCH 2/2] Fix NameFromCommandArgs when passing command after -- --- pkg/oc/cli/create/create.go | 16 ++++++++++------ test/cmd/create.sh | 4 +++- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/pkg/oc/cli/create/create.go b/pkg/oc/cli/create/create.go index 5713a708f170..ec7b24de4ef1 100644 --- a/pkg/oc/cli/create/create.go +++ b/pkg/oc/cli/create/create.go @@ -1,8 +1,6 @@ package create import ( - "fmt" - "github.com/spf13/cobra" "github.com/openshift/origin/pkg/oc/util/ocscheme" @@ -36,7 +34,7 @@ func NewCreateSubcommandOptions(ioStreams genericclioptions.IOStreams) *CreateSu } func (o *CreateSubcommandOptions) Complete(f genericclioptions.RESTClientGetter, cmd *cobra.Command, args []string) error { - name, err := NameFromCommandArgs(args) + name, err := NameFromCommandArgs(cmd, args) if err != nil { return err } @@ -60,9 +58,15 @@ func (o *CreateSubcommandOptions) Complete(f genericclioptions.RESTClientGetter, } // NameFromCommandArgs is a utility function for commands that assume the first argument is a resource name -func NameFromCommandArgs(args []string) (string, error) { - if len(args) != 1 { - return "", fmt.Errorf("exactly one NAME is required, got %d", len(args)) +func NameFromCommandArgs(cmd *cobra.Command, args []string) (string, error) { + argsLen := cmd.ArgsLenAtDash() + // ArgsLenAtDash returns -1 when -- was not specified + if argsLen == -1 { + argsLen = len(args) + } + if argsLen != 1 { + return "", cmdutil.UsageErrorf(cmd, "exactly one NAME is required, got %d", argsLen) } return args[0], nil + } diff --git a/test/cmd/create.sh b/test/cmd/create.sh index 4a9cc975d8b5..8f74cbcc38dc 100755 --- a/test/cmd/create.sh +++ b/test/cmd/create.sh @@ -13,6 +13,8 @@ trap os::test::junit::reconcile_output EXIT os::test::junit::declare_suite_start "cmd/create" # validate --dry-run outputs correct success message os::cmd::expect_success_and_text 'oc create quota quota --dry-run' 'resourcequota/quota created \(dry run\)' +# validate -- works in create +os::cmd::expect_success_and_text 'oc create deploymentconfig sleep --image=busybox -- /bin/sleep infinity' 'deploymentconfig.apps.openshift.io/sleep created' echo "oc create: ok" -os::test::junit::declare_suite_end \ No newline at end of file +os::test::junit::declare_suite_end