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

prevent removal of valid arguments #95

Merged
merged 1 commit into from
Apr 28, 2015

Conversation

deads2k
Copy link
Contributor

@deads2k deads2k commented Apr 24, 2015

running a command like:

openshift admin policy add-role-to-user admin my-user

where admin and my-user are arguments to the openshift admin policy add-role-to-user command, removes the admin argument (args[4]).

This pull stops removing more than one token from the args for command matches.

@smarterclayton Related to openshift/origin#1894

@smarterclayton
Copy link
Collaborator

Add a test case please.

@deads2k deads2k force-pushed the deads-prevent-extra-removal branch from 800a992 to 8c78327 Compare April 24, 2015 17:07
@deads2k
Copy link
Contributor Author

deads2k commented Apr 24, 2015

test added.

@smarterclayton
Copy link
Collaborator

LGTM. @brendandburns can you review as well? Impacts kube in a few places.

newargs = append(newargs, y)
} else {
removedFirstX = true
Copy link
Collaborator

Choose a reason for hiding this comment

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

Being always the bikeshedder, I like this better (and think it's faster, more readable, more efficient...) What do you think?

https://gist.github.com/eparis/458542ddda01fa9850f9

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you think?

I'm not against it, except for it not working:

[deads@deads-dev-01 cobra]$ go test
Error: unknown command "one"
Run 'print help' for usage.
--- FAIL: TestChildSameName (0.00 seconds)
    cobra_test.go:345: Wrong command called
    cobra_test.go:348: Command didn't parse correctly

I checked in a similar version that passes.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@deads2k yeah, so I guess my version was actually mutating the original slice, rather than creating a new slice with just the correct data. Thanks for the new (working) version!

@deads2k deads2k force-pushed the deads-prevent-extra-removal branch from 8c78327 to 36aee64 Compare April 28, 2015 11:58
@smarterclayton
Copy link
Collaborator

LGTM

smarterclayton added a commit that referenced this pull request Apr 28, 2015
@smarterclayton smarterclayton merged commit af6b555 into spf13:master Apr 28, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants