func runMockCmd(cmd *cobra.Command, args []string) error {
	cmdFlags := cmd.Flags()
	if err := cmdFlags.Parse(args); err != nil {
		return fmt.Errorf("failed to parse arguments: %s", err)
	}
	return cmd.RunE(cmd, cmdFlags.Args())
}
runMockCmd is a helper function which parses flags and invokes a given mock
command.
package cmd
import (
	"bytes"
	"fmt"
	"testing"
	"github.com/spf13/cobra"
)
func newMockCmd(cmd *cobra.Command, input string) *cobra.Command {
	inStream := bytes.NewBufferString(input)
	outStream := new(bytes.Buffer)
	errStream := new(bytes.Buffer)
	cmd.SetIn(inStream)
	cmd.SetOut(outStream)
	cmd.SetErr(errStream)
	return cmd
}
func assertMockCmd(t *testing.T, cmd *cobra.Command, args []string, ok bool, want string) {
	err := runMockCmd(cmd, args)
	stderr := mockErr(cmd)
	if ok && err != nil {
		t.Fatalf("unexpected err = %s, stderr: \n%s", err, stderr)
	}
	stdout := mockOut(cmd)
	if !ok && err == nil {
		t.Fatalf("expected to return an error, but no error, stdout: \n%s", stdout)
	}
	if stdout != want {
		t.Fatalf("got:\n%s\nwant:\n%s", stdout, want)
	}
}