Skip to content

Commit cd7d048

Browse files
Merge pull request #20730 from soltysh/fix_create
Fix NameFromCommandArgs when passing command after --
2 parents 3f04e0b + 7b24607 commit cd7d048

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

pkg/oc/cli/create/create.go

+10-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package create
22

33
import (
4-
"fmt"
5-
64
"github.com/spf13/cobra"
75

86
"github.com/openshift/origin/pkg/oc/util/ocscheme"
@@ -36,7 +34,7 @@ func NewCreateSubcommandOptions(ioStreams genericclioptions.IOStreams) *CreateSu
3634
}
3735

3836
func (o *CreateSubcommandOptions) Complete(f genericclioptions.RESTClientGetter, cmd *cobra.Command, args []string) error {
39-
name, err := NameFromCommandArgs(args)
37+
name, err := NameFromCommandArgs(cmd, args)
4038
if err != nil {
4139
return err
4240
}
@@ -60,9 +58,15 @@ func (o *CreateSubcommandOptions) Complete(f genericclioptions.RESTClientGetter,
6058
}
6159

6260
// NameFromCommandArgs is a utility function for commands that assume the first argument is a resource name
63-
func NameFromCommandArgs(args []string) (string, error) {
64-
if len(args) != 1 {
65-
return "", fmt.Errorf("exactly one NAME is required, got %d", len(args))
61+
func NameFromCommandArgs(cmd *cobra.Command, args []string) (string, error) {
62+
argsLen := cmd.ArgsLenAtDash()
63+
// ArgsLenAtDash returns -1 when -- was not specified
64+
if argsLen == -1 {
65+
argsLen = len(args)
66+
}
67+
if argsLen != 1 {
68+
return "", cmdutil.UsageErrorf(cmd, "exactly one NAME is required, got %d", argsLen)
6669
}
6770
return args[0], nil
71+
6872
}

test/cmd/create.sh

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ trap os::test::junit::reconcile_output EXIT
1313
os::test::junit::declare_suite_start "cmd/create"
1414
# validate --dry-run outputs correct success message
1515
os::cmd::expect_success_and_text 'oc create quota quota --dry-run' 'resourcequota/quota created \(dry run\)'
16+
# validate -- works in create
17+
os::cmd::expect_success_and_text 'oc create deploymentconfig sleep --image=busybox -- /bin/sleep infinity' 'deploymentconfig.apps.openshift.io/sleep created'
1618

1719
echo "oc create: ok"
18-
os::test::junit::declare_suite_end
20+
os::test::junit::declare_suite_end

vendor/k8s.io/kubernetes/pkg/kubectl/cmd/create/create.go

+7-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)