Go: Add a function for go mod init

This commit is contained in:
Michael B. Gale
2024-01-26 13:42:20 +00:00
parent 1bf747ef3a
commit b5ae8ace0d
2 changed files with 8 additions and 3 deletions

View File

@@ -3,7 +3,6 @@ package project
import (
"log"
"os"
"os/exec"
"path/filepath"
"regexp"
"sort"
@@ -58,8 +57,7 @@ func checkDirsNested(inputDirs []string) (string, bool) {
func initGoModForLegacyProject(path string) {
log.Printf("Project appears to be a legacy Go project, attempting to initialize go.mod")
modInit := exec.Command("go", "mod", "init", "codeql/auto-project")
modInit.Dir = path
modInit := toolchain.InitModule(path)
if !util.RunCmd(modInit) {
log.Printf("Failed to initialize go.mod file for this project.")

View File

@@ -78,3 +78,10 @@ func TidyModule(path string) *exec.Cmd {
cmd.Dir = path
return cmd
}
// Run `go mod init` in the directory given by `path`.
func InitModule(path string) *exec.Cmd {
modInit := exec.Command("go", "mod", "init", "codeql/auto-project")
modInit.Dir = path
return modInit
}