From 3c335a453d196524dd5461201cc2532f5215da43 Mon Sep 17 00:00:00 2001 From: Siriwat Uamngamsup Date: Mon, 7 May 2018 19:41:58 +0700 Subject: [PATCH] Replace Tool.Dir with new property Tool.Path --- realize/projects.go | 16 ++++++++++------ realize/server.go | 2 +- realize/tools.go | 1 + 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/realize/projects.go b/realize/projects.go index 264fd47..f2a5f0a 100644 --- a/realize/projects.go +++ b/realize/projects.go @@ -5,7 +5,6 @@ import ( "bytes" "errors" "fmt" - "github.com/fsnotify/fsnotify" "log" "math/big" "os" @@ -17,6 +16,8 @@ import ( "strings" "sync" "time" + + "github.com/fsnotify/fsnotify" ) var ( @@ -586,18 +587,18 @@ func (p *Project) run(path string, stream chan Response, stop <-chan bool) (err args = append(args, a...) } dirPath := os.Getenv("GOBIN") - if p.Tools.Run.Dir != "" { - dirPath, _ = filepath.Abs(p.Tools.Run.Dir) + if p.Tools.Run.Path != "" { + dirPath, _ = filepath.Abs(p.Tools.Run.Path) } name := filepath.Base(path) - if path == "." && p.Tools.Run.Dir == "" { + if path == "." && p.Tools.Run.Path == "" { name = filepath.Base(Wdir()) - } else if p.Tools.Run.Dir != "" { + } else if p.Tools.Run.Path != "" { name = filepath.Base(dirPath) } path = filepath.Join(dirPath, name) if p.Tools.Run.Method != "" { - path = p.Tools.Run.Method + path = p.Tools.Run.Method } if _, err := os.Stat(path); err == nil { build = exec.Command(path, args...) @@ -618,6 +619,9 @@ func (p *Project) run(path string, stream chan Response, stop <-chan bool) (err if err != nil { return err } + if p.Tools.Run.Dir != "" { + build.Dir = p.Tools.Run.Dir + } if err := build.Start(); err != nil { return err } diff --git a/realize/server.go b/realize/server.go index cbc3e5f..a2cb26c 100644 --- a/realize/server.go +++ b/realize/server.go @@ -5,6 +5,7 @@ package realize import ( "bytes" "encoding/json" + "errors" "fmt" "github.com/labstack/echo" "github.com/labstack/echo/middleware" @@ -14,7 +15,6 @@ import ( "os/exec" "runtime" "strconv" - "errors" ) // Dafault host and port diff --git a/realize/tools.go b/realize/tools.go index 1efe09b..641aed5 100644 --- a/realize/tools.go +++ b/realize/tools.go @@ -14,6 +14,7 @@ import ( type Tool struct { Args []string `yaml:"args,omitempty" json:"args,omitempty"` Method string `yaml:"method,omitempty" json:"method,omitempty"` + Path string `yaml:"path,omitempty" json:"dir,omitempty"` Dir string `yaml:"dir,omitempty" json:"dir,omitempty"` //wdir of the command Status bool `yaml:"status,omitempty" json:"status,omitempty"` Output bool `yaml:"output,omitempty" json:"output,omitempty"`