@@ -137,9 +137,14 @@ func SupportsWorkspaces() bool {
137
137
return GetEnvGoSemVer ().IsAtLeast (V1_18 )
138
138
}
139
139
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
+
140
145
// Run `go mod tidy -e` in the directory given by `path`.
141
146
func TidyModule (path string ) * exec.Cmd {
142
- cmd := exec . Command ( "go" , "mod" , "tidy" , "-e" )
147
+ cmd := GoCommand ( "mod" , "tidy" , "-e" )
143
148
cmd .Dir = path
144
149
return cmd
145
150
}
@@ -159,21 +164,21 @@ func InitModule(path string) *exec.Cmd {
159
164
}
160
165
}
161
166
162
- modInit := exec . Command ( "go" , "mod" , "init" , moduleName )
167
+ modInit := GoCommand ( "mod" , "init" , moduleName )
163
168
modInit .Dir = path
164
169
return modInit
165
170
}
166
171
167
172
// Constructs a command to run `go mod vendor -e` in the directory given by `path`.
168
173
func VendorModule (path string ) * exec.Cmd {
169
- modVendor := exec . Command ( "go" , "mod" , "vendor" , "-e" )
174
+ modVendor := GoCommand ( "mod" , "vendor" , "-e" )
170
175
modVendor .Dir = path
171
176
return modVendor
172
177
}
173
178
174
179
// Constructs a command to run `go version`.
175
180
func Version () * exec.Cmd {
176
- version := exec . Command ( "go" , "version" )
181
+ version := GoCommand ( "version" )
177
182
return version
178
183
}
179
184
@@ -209,7 +214,7 @@ func RunListWithEnv(format string, patterns []string, additionalEnv []string, fl
209
214
func ListWithEnv (format string , patterns []string , additionalEnv []string , flags ... string ) * exec.Cmd {
210
215
args := append ([]string {"list" , "-e" , "-f" , format }, flags ... )
211
216
args = append (args , patterns ... )
212
- cmd := exec . Command ( "go" , args ... )
217
+ cmd := GoCommand ( args ... )
213
218
cmd .Env = append (os .Environ (), additionalEnv ... )
214
219
return cmd
215
220
}
0 commit comments