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

Fix NameFromCommandArgs when passing command after -- #20730

Merged
merged 2 commits into from
Aug 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions pkg/oc/cli/create/create.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package create

import (
"fmt"

"github.com/spf13/cobra"

"github.com/openshift/origin/pkg/oc/util/ocscheme"
Expand Down Expand Up @@ -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
}
Expand All @@ -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

}
4 changes: 3 additions & 1 deletion test/cmd/create.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


echo "oc create: ok"
os::test::junit::declare_suite_end
os::test::junit::declare_suite_end
9 changes: 7 additions & 2 deletions vendor/k8s.io/kubernetes/pkg/kubectl/cmd/create/create.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.