diff --git a/watcher/exec.go b/watcher/exec.go index 2797c88..21a2302 100644 --- a/watcher/exec.go +++ b/watcher/exec.go @@ -34,10 +34,10 @@ func (p *Project) goRun(channel chan bool, runner chan bool, wr *sync.WaitGroup) if path != "" { build = exec.Command(path, params...) } else { - if _, err := os.Stat(filepath.Join(os.Getenv("GOBIN"), filepath.Base(p.path))); err == nil { - build = exec.Command(filepath.Join(os.Getenv("GOBIN"), filepath.Base(p.path)), params...) - } else if _, err := os.Stat(filepath.Join(os.Getenv("GOBIN"), filepath.Base(p.path)) + ".exe"); err == nil { - build = exec.Command(filepath.Join(os.Getenv("GOBIN"), filepath.Base(p.path))+".exe", params...) + if _, err := os.Stat(filepath.Join(getEnvPath("GOBIN"), filepath.Base(p.path))); err == nil { + build = exec.Command(filepath.Join(getEnvPath("GOBIN"), filepath.Base(p.path)), params...) + } else if _, err := os.Stat(filepath.Join(getEnvPath("GOBIN"), filepath.Base(p.path)) + ".exe"); err == nil { + build = exec.Command(filepath.Join(getEnvPath("GOBIN"), filepath.Base(p.path))+".exe", params...) } else { p.Buffer.StdLog = append(p.Buffer.StdLog, BufferOut{Time: time.Now(), Text: "Can't run a not compiled project"}) p.Fatal(err, "Can't run a not compiled project", ":") @@ -116,7 +116,7 @@ func (p *Project) goBuild() (string, error) { func (p *Project) goInstall() (string, error) { var out bytes.Buffer var stderr bytes.Buffer - err := os.Setenv("GOBIN", filepath.Join(os.Getenv("GOPATH"), "bin")) + err := os.Setenv("GOBIN", filepath.Join(getEnvPath("GOPATH"), "bin")) if err != nil { return "", err } diff --git a/watcher/utils.go b/watcher/utils.go index 9535a2d..4509080 100644 --- a/watcher/utils.go +++ b/watcher/utils.go @@ -3,6 +3,8 @@ package watcher import ( "errors" "fmt" + "os" + "path/filepath" "time" "github.com/tockins/realize/style" @@ -46,3 +48,13 @@ func inArray(str string, list []string) bool { func (w logWriter) Write(bytes []byte) (int, error) { return fmt.Print(style.Yellow.Regular("[") + time.Now().Format("15:04:05") + style.Yellow.Regular("]") + string(bytes)) } + +// getEnvPath returns the first path found in env or empty string +func getEnvPath(env string) string { + path := filepath.SplitList(os.Getenv(env)) + if len(path) == 0 { + return "" + } else { + return path[0] + } +}