@@ -137,9 +137,14 @@ func SupportsWorkspaces() bool {
137137 return GetEnvGoSemVer ().IsAtLeast (V1_18 )
138138}
139139
140+ // Constructs a `*exec.Cmd` for `go` with the specified arguments.
141+ func GoCommand (arg ... string ) * exec.Cmd {
142+ return exec .Command ("go" , arg ... )
143+ }
144+
140145// Run `go mod tidy -e` in the directory given by `path`.
141146func TidyModule (path string ) * exec.Cmd {
142- cmd := exec . Command ( "go" , "mod" , "tidy" , "-e" )
147+ cmd := GoCommand ( "mod" , "tidy" , "-e" )
143148 cmd .Dir = path
144149 return cmd
145150}
@@ -159,21 +164,21 @@ func InitModule(path string) *exec.Cmd {
159164 }
160165 }
161166
162- modInit := exec . Command ( "go" , "mod" , "init" , moduleName )
167+ modInit := GoCommand ( "mod" , "init" , moduleName )
163168 modInit .Dir = path
164169 return modInit
165170}
166171
167172// Constructs a command to run `go mod vendor -e` in the directory given by `path`.
168173func VendorModule (path string ) * exec.Cmd {
169- modVendor := exec . Command ( "go" , "mod" , "vendor" , "-e" )
174+ modVendor := GoCommand ( "mod" , "vendor" , "-e" )
170175 modVendor .Dir = path
171176 return modVendor
172177}
173178
174179// Constructs a command to run `go version`.
175180func Version () * exec.Cmd {
176- version := exec . Command ( "go" , "version" )
181+ version := GoCommand ( "version" )
177182 return version
178183}
179184
@@ -209,7 +214,7 @@ func RunListWithEnv(format string, patterns []string, additionalEnv []string, fl
209214func ListWithEnv (format string , patterns []string , additionalEnv []string , flags ... string ) * exec.Cmd {
210215 args := append ([]string {"list" , "-e" , "-f" , format }, flags ... )
211216 args = append (args , patterns ... )
212- cmd := exec . Command ( "go" , args ... )
217+ cmd := GoCommand ( args ... )
213218 cmd .Env = append (os .Environ (), additionalEnv ... )
214219 return cmd
215220}
0 commit comments