Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@probablycorey
Copy link
Contributor

In our tests we call RunCommand like this output, err := RunCommand(issueListCmd, "issue list"). I was running into a problem where I would call RunCommand with the wrong command! For example, instead of RunCommand(issueListCmd, "issue list") I would call RunCommand(OMGWrongCmd, "issue list"). This caused lots of problems because stderr and stdout weren't being captured in a way I could see. I was very confused.

Could I have avoided this problem I was more thorough? Yes, but as we all know humans make errors especially if their name is @probablycorey. So I propose we protect our future selves by changing the arguments to RunCommand to func RunCommand(args string) (*cmdOut, error). We can use cobra's ability to parse raw strings to figure out which command should be run.

@mislav @vilmibm what do you think?

P.S. Moving RunCommand to testing.go seems to make sense too.

@probablycorey probablycorey self-assigned this May 1, 2020
Copy link
Contributor

@vilmibm vilmibm left a comment

Choose a reason for hiding this comment

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

I'm very in favor of this.

Copy link
Contributor

@mislav mislav left a comment

Choose a reason for hiding this comment

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

I support this improvement!

To avoid changing all current call points, you could perhaps still accept the 1st argument but ignore it. New callers might simply pass nil.

When we address #759, I suspect that the RunCommand approach will change as well. But until then this is worthwhile.

@probablycorey
Copy link
Contributor Author

I went ahead and updated all the call points because it wasn't difficult and it was obviously easy to test because they are all called inside tests!

@probablycorey probablycorey merged commit 39e6f41 into master May 5, 2020
@probablycorey probablycorey deleted the a-better-runcommand branch May 5, 2020 16:50
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.

4 participants