Skip to content

Commit b5ae8ac

Browse files
committed
Go: Add a function for go mod init
1 parent 1bf747e commit b5ae8ac

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

go/extractor/project/project.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package project
33
import (
44
"log"
55
"os"
6-
"os/exec"
76
"path/filepath"
87
"regexp"
98
"sort"
@@ -58,8 +57,7 @@ func checkDirsNested(inputDirs []string) (string, bool) {
5857
func initGoModForLegacyProject(path string) {
5958
log.Printf("Project appears to be a legacy Go project, attempting to initialize go.mod")
6059

61-
modInit := exec.Command("go", "mod", "init", "codeql/auto-project")
62-
modInit.Dir = path
60+
modInit := toolchain.InitModule(path)
6361

6462
if !util.RunCmd(modInit) {
6563
log.Printf("Failed to initialize go.mod file for this project.")

go/extractor/toolchain/toolchain.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,10 @@ func TidyModule(path string) *exec.Cmd {
7878
cmd.Dir = path
7979
return cmd
8080
}
81+
82+
// Run `go mod init` in the directory given by `path`.
83+
func InitModule(path string) *exec.Cmd {
84+
modInit := exec.Command("go", "mod", "init", "codeql/auto-project")
85+
modInit.Dir = path
86+
return modInit
87+
}

0 commit comments

Comments
 (0)