mirror of
https://github.com/github/codeql.git
synced 2026-04-23 15:55:18 +02:00
Go: Add a function for go mod init
This commit is contained in:
@@ -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.")
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user