func ListVendoredModules(moduleDir string, writer io.Writer) error {
	return executeGoCommand([]string{"mod", "vendor", "-v", "-e"}, withDir(moduleDir), withStderr(writer))
}
ListVendoredModules executes `go mod vendor -v` and writes the output to a given writer.
See https://golang.org/ref/mod#go-mod-vendor.
package gocmd
import (
	"bytes"
	"encoding/json"
	"fmt"
	"io"
	"os"
	"os/exec"
	"strings"
	"github.com/rs/zerolog/log"
)
func GetVersion() (string, error) {
	buf := new(bytes.Buffer)
	err := executeGoCommand([]string{"version"}, withStdout(buf))
	if err != nil {
		return "", err
	}
	output := buf.String()
	fields := strings.Fields(output)
	if len(fields) != 4 {
		return "", fmt.Errorf("expected four fields in output, but got %d: %s", len(fields), output)
	}
	if fields[0] != "go" || fields[1] != "version" {
		return "", fmt.Errorf("unexpected output format: %s", output)
	}
	return fields[2], nil
}
func GetEnv() (map[string]string, error) {
	buf := new(bytes.Buffer)
	err := executeGoCommand([]string{"env", "-json"}, withStdout(buf))
	if err != nil {
		return nil, err
	}
	var env map[string]string
	err = json.NewDecoder(buf).Decode(&env)
	if err != nil {
		return nil, err
	}
	return env, nil
}
func ListModule(moduleDir string, writer io.Writer) error {
	return executeGoCommand([]string{"list", "-mod", "readonly", "-json", "-m"}, withDir(moduleDir), withStdout(writer))
}
func ListModules(moduleDir string, writer io.Writer) error {
	return executeGoCommand([]string{"list", "-mod", "readonly", "-json", "-m", "all"}, withDir(moduleDir), withStdout(writer))
}
func ListPackage(moduleDir, packagePattern string, writer io.Writer) error {
	return executeGoCommand([]string{"list", "-json", "-e", packagePattern},
		withDir(moduleDir),
		withStdout(writer),
		withStderr(os.Stderr))
}
func ListPackages(moduleDir, packagePattern string, writer io.Writer) error {
	return executeGoCommand([]string{"list", "-deps", "-json", packagePattern},
		withDir(moduleDir),
		withStdout(writer),
		withStderr(os.Stderr),
	)
}