Skip to content

Commit

Permalink
Merge pull request #20730 from soltysh/fix_create
Browse files Browse the repository at this point in the history
Fix NameFromCommandArgs when passing command after --
  • Loading branch information
openshift-merge-robot committed Aug 23, 2018
2 parents 3f04e0b + 7b24607 commit cd7d048
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
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'

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.

0 comments on commit cd7d048

Please sign in to comment.