Skip to content

Commit 2d8d977

Browse files
committed
Factor out depMode calculation
1 parent d613bc8 commit 2d8d977

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

go/extractor/cli/go-autobuilder/go-autobuilder.go

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,22 @@ func checkVendor() bool {
221221
return true
222222
}
223223

224+
func getDepMode() DependencyInstallerMode {
225+
if util.FileExists("go.mod") {
226+
log.Println("Found go.mod, enabling go modules")
227+
return GoGetWithModules
228+
}
229+
if util.FileExists("Gopkg.toml") {
230+
log.Println("Found Gopkg.toml, using dep instead of go get")
231+
return Dep
232+
}
233+
if util.FileExists("glide.yaml") {
234+
log.Println("Found glide.yaml, enabling go modules")
235+
return Glide
236+
}
237+
return GoGetNoModules
238+
}
239+
224240
func main() {
225241
if len(os.Args) > 1 {
226242
usage()
@@ -247,15 +263,14 @@ func main() {
247263

248264
// determine how to install dependencies and whether a GOPATH needs to be set up before
249265
// extraction
250-
depMode := GoGetNoModules
266+
depMode := getDepMode()
251267
modMode := ModUnset
252268
needGopath := true
253269
goDirectiveFound := false
254270
if _, present := os.LookupEnv("GO111MODULE"); !present {
255271
os.Setenv("GO111MODULE", "auto")
256272
}
257-
if util.FileExists("go.mod") {
258-
depMode = GoGetWithModules
273+
if depMode == GoGetWithModules {
259274
needGopath = false
260275
versionRe := regexp.MustCompile(`(?m)^go[ \t\r]+([0-9]+\.[0-9]+)$`)
261276
goMod, err := ioutil.ReadFile("go.mod")
@@ -273,13 +288,6 @@ func main() {
273288
}
274289
}
275290
}
276-
log.Println("Found go.mod, enabling go modules")
277-
} else if util.FileExists("Gopkg.toml") {
278-
depMode = Dep
279-
log.Println("Found Gopkg.toml, using dep instead of go get")
280-
} else if util.FileExists("glide.yaml") {
281-
depMode = Glide
282-
log.Println("Found glide.yaml, enabling go modules")
283291
}
284292

285293
if depMode == GoGetWithModules {

0 commit comments

Comments
 (0)