|
|
@ -141,23 +141,26 @@ func createGoModFileIfNeed(dir string) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_, hasGoMod := util.FindGoModPath(dir)
|
|
|
|
_, hasGoMod := util.FindGoModPath(dir)
|
|
|
|
if !hasGoMod {
|
|
|
|
if hasGoMod {
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
gopath := os.Getenv("GOPATH")
|
|
|
|
gopath := os.Getenv("GOPATH")
|
|
|
|
parent := path.Join(gopath, "src")
|
|
|
|
parent := path.Join(gopath, "src")
|
|
|
|
pos := strings.Index(absDir, parent)
|
|
|
|
pos := strings.Index(absDir, parent)
|
|
|
|
if pos < 0 {
|
|
|
|
if pos >= 0 {
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
moduleName := absDir[len(filepath.Dir(absDir))+1:]
|
|
|
|
moduleName := absDir[len(filepath.Dir(absDir))+1:]
|
|
|
|
cmd := exec.Command("go", "mod", "init", moduleName)
|
|
|
|
cmd := exec.Command("go", "mod", "init", moduleName)
|
|
|
|
cmd.Dir = dir
|
|
|
|
cmd.Dir = dir
|
|
|
|
var stdout, stderr bytes.Buffer
|
|
|
|
var stdout, stderr bytes.Buffer
|
|
|
|
cmd.Stdout = &stdout
|
|
|
|
cmd.Stdout = &stdout
|
|
|
|
cmd.Stderr = &stderr
|
|
|
|
cmd.Stderr = &stderr
|
|
|
|
err := cmd.Run()
|
|
|
|
if err = cmd.Run(); err != nil {
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
fmt.Println(err.Error())
|
|
|
|
fmt.Println(err.Error())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
outStr, errStr := string(stdout.Bytes()), string(stderr.Bytes())
|
|
|
|
outStr, errStr := string(stdout.Bytes()), string(stderr.Bytes())
|
|
|
|
fmt.Printf(outStr + "\n" + errStr)
|
|
|
|
fmt.Printf(outStr + "\n" + errStr)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|