@@ -51,6 +51,7 @@ func GetVersion() (string, error) {
5151}
5252
5353// GetEnv executes `go env -json` and returns the result as a map.
54+ // See https://pkg.go.dev/cmd/go#hdr-Print_Go_environment_information.
5455func GetEnv () (map [string ]string , error ) {
5556 buf := new (bytes.Buffer )
5657 err := executeGoCommand ([]string {"env" , "-json" }, withStdout (buf ))
@@ -67,9 +68,9 @@ func GetEnv() (map[string]string, error) {
6768 return env , nil
6869}
6970
70- // GetModule executes `go list -json -m` and writes the output to a given writer.
71+ // ListModule executes `go list -json -m` and writes the output to a given writer.
7172// See https://golang.org/ref/mod#go-list-m
72- func GetModule (moduleDir string , writer io.Writer ) error {
73+ func ListModule (moduleDir string , writer io.Writer ) error {
7374 return executeGoCommand ([]string {"list" , "-mod" , "readonly" , "-json" , "-m" }, withDir (moduleDir ), withStdout (writer ))
7475}
7576
@@ -80,6 +81,7 @@ func ListModules(moduleDir string, writer io.Writer) error {
8081}
8182
8283// ListPackage executes `go list -json -e <PATTERN>` and writes the output to a given writer.
84+ // See // See https://golang.org/cmd/go/#hdr-List_packages_or_modules.
8385func ListPackage (moduleDir , packagePattern string , writer io.Writer ) error {
8486 return executeGoCommand ([]string {"list" , "-json" , "-e" , packagePattern },
8587 withDir (moduleDir ),
@@ -88,7 +90,7 @@ func ListPackage(moduleDir, packagePattern string, writer io.Writer) error {
8890}
8991
9092// ListPackages executes `go list -deps -json <PATTERN>` and writes the output to a given writer.
91- // See https://golang.org/cmd/go/#hdr-List_packages_or_modules
93+ // See https://golang.org/cmd/go/#hdr-List_packages_or_modules.
9294func ListPackages (moduleDir , packagePattern string , writer io.Writer ) error {
9395 return executeGoCommand ([]string {"list" , "-deps" , "-json" , packagePattern },
9496 withDir (moduleDir ),
@@ -98,19 +100,19 @@ func ListPackages(moduleDir, packagePattern string, writer io.Writer) error {
98100}
99101
100102// ListVendoredModules executes `go mod vendor -v` and writes the output to a given writer.
101- // See https://golang.org/ref/mod#go-mod-vendor
103+ // See https://golang.org/ref/mod#go-mod-vendor.
102104func ListVendoredModules (moduleDir string , writer io.Writer ) error {
103105 return executeGoCommand ([]string {"mod" , "vendor" , "-v" , "-e" }, withDir (moduleDir ), withStderr (writer ))
104106}
105107
106108// GetModuleGraph executes `go mod graph` and writes the output to a given writer.
107- // See https://golang.org/ref/mod#go-mod-graph
109+ // See https://golang.org/ref/mod#go-mod-graph.
108110func GetModuleGraph (moduleDir string , writer io.Writer ) error {
109111 return executeGoCommand ([]string {"mod" , "graph" }, withDir (moduleDir ), withStdout (writer ))
110112}
111113
112114// ModWhy executes `go mod why -m -vendor` and writes the output to a given writer.
113- // See https://golang.org/ref/mod#go-mod-why
115+ // See https://golang.org/ref/mod#go-mod-why.
114116func ModWhy (moduleDir string , modules []string , writer io.Writer ) error {
115117 return executeGoCommand (
116118 append ([]string {"mod" , "why" , "-m" , "-vendor" }, modules ... ),
@@ -121,11 +123,13 @@ func ModWhy(moduleDir string, modules []string, writer io.Writer) error {
121123}
122124
123125// LoadModulesFromBinary executes `go version -m` and writes the output to a given writer.
126+ // See https://golang.org/ref/mod#go-version-m.
124127func LoadModulesFromBinary (binaryPath string , writer io.Writer ) error {
125128 return executeGoCommand ([]string {"version" , "-m" , binaryPath }, withStdout (writer ))
126129}
127130
128131// DownloadModules executes `go mod download -json` and writes the output to the given writers.
132+ // See https://golang.org/ref/mod#go-mod-download.
129133func DownloadModules (modules []string , stdout , stderr io.Writer ) error {
130134 return executeGoCommand (
131135 append ([]string {"mod" , "download" , "-json" }, modules ... ),
@@ -167,5 +171,10 @@ func executeGoCommand(args []string, options ...commandOption) error {
167171 Str ("dir" , cmd .Dir ).
168172 Msg ("executing command" )
169173
170- return cmd .Run ()
174+ err := cmd .Run ()
175+ if err != nil {
176+ return fmt .Errorf ("command `%s` failed: %w" , cmd .String (), err )
177+ }
178+
179+ return nil
171180}
0 commit comments