From 74366bfadafa06608d0f22e45f7f0cf0cec0ca82 Mon Sep 17 00:00:00 2001 From: asoseil Date: Mon, 20 Nov 2017 18:33:24 +0100 Subject: [PATCH] #130 fixed --- realize/projects.go | 23 +++++++++++++---------- realize/schema.go | 4 +++- realize/tools.go | 15 ++++++++++++--- 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/realize/projects.go b/realize/projects.go index fb8c5f0..7ffb1b2 100644 --- a/realize/projects.go +++ b/realize/projects.go @@ -75,11 +75,11 @@ type BufferOut struct { Errors []string `json:"errors"` } -type ProjectI interface{ +type ProjectI interface { Setup() Watch(chan os.Signal) - Run(string, chan Response,<-chan bool) - Restart(FileWatcher,string,<-chan bool) + Run(string, chan Response, <-chan bool) + Restart(FileWatcher, string, <-chan bool) } // Setup a project @@ -210,7 +210,7 @@ func (p *Project) Restart(watcher FileWatcher, path string, stop <-chan bool) { // Prevent fake events on polling startup p.init = true // prevent errors using realize without config with only run flag - if p.Tools.Run && !p.Tools.Install.Status && !p.Tools.Build.Status { + if p.Tools.Run.Status && !p.Tools.Install.Status && !p.Tools.Build.Status { p.Tools.Install.Status = true } if done { @@ -238,7 +238,7 @@ func (p *Project) Restart(watcher FileWatcher, path string, stop <-chan bool) { if done { return } - if install.Err == nil && build.Err == nil && p.Tools.Run { + if install.Err == nil && build.Err == nil && p.Tools.Run.Status { var start time.Time result := make(chan Response) go func() { @@ -309,12 +309,15 @@ func (p *Project) Run(path string, stream chan Response, stop <-chan bool) (err }) args = append(args, a...) } - gobin := os.Getenv("GOBIN") - dirPath := filepath.Base(path) - if path == "." { - dirPath = filepath.Base(Wdir()) + dirPath := os.Getenv("GOBIN") + if p.Tools.Run.Dir != "" { + dirPath, _ = filepath.Abs(p.Tools.Run.Dir) } - path = filepath.Join(gobin, dirPath) + name := filepath.Base(path) + if path == "." { + name = filepath.Base(Wdir()) + } + path = filepath.Join(dirPath, name) if _, err := os.Stat(path); err == nil { build = exec.Command(path, args...) } else if _, err := os.Stat(path + RExtWin); err == nil { diff --git a/realize/schema.go b/realize/schema.go index c78b946..3df05a4 100644 --- a/realize/schema.go +++ b/realize/schema.go @@ -61,7 +61,9 @@ func (s *Schema) New(c *cli.Context) Project { Install: Tool{ Status: c.Bool("install"), }, - Run: c.Bool("run"), + Run: Tool{ + Status: c.Bool("run"), + }, }, Args: params(c), Watcher: Watch{ diff --git a/realize/tools.go b/realize/tools.go index 7e9b0ae..d724aa0 100644 --- a/realize/tools.go +++ b/realize/tools.go @@ -12,6 +12,7 @@ import ( type Tool struct { Args []string `yaml:"args,omitempty" json:"args,omitempty"` Method string `yaml:"method,omitempty" json:"method,omitempty"` + Dir string `yaml:"dir,omitempty" json:"dir,omitempty"` //wdir of the command Status bool `yaml:"status,omitempty" json:"status,omitempty"` dir bool isTool bool @@ -30,7 +31,7 @@ type Tools struct { Generate Tool `yaml:"generate,omitempty" json:"generate,omitempty"` Install Tool `yaml:"install,omitempty" json:"install,omitempty"` Build Tool `yaml:"build,omitempty" json:"build,omitempty"` - Run bool `yaml:"run,omitempty" json:"run,omitempty"` + Run Tool `yaml:"run,omitempty" json:"run,omitempty"` } // Setup go tools @@ -111,7 +112,11 @@ func (t *Tool) Exec(path string, stop <-chan bool) (response Response) { done := make(chan error) args = append(t.cmd, t.Args...) cmd := exec.Command(args[0], args[1:]...) - cmd.Dir = path + if t.Dir != "" { + cmd.Dir, _ = filepath.Abs(t.Dir) + } else { + cmd.Dir = path + } cmd.Stdout = &out cmd.Stderr = &stderr // Start command @@ -143,7 +148,11 @@ func (t *Tool) Compile(path string, stop <-chan bool) (response Response) { done := make(chan error) args := append(t.cmd, t.Args...) cmd := exec.Command(args[0], args[1:]...) - cmd.Dir = filepath.Dir(path) + if t.Dir != "" { + cmd.Dir, _ = filepath.Abs(t.Dir) + } else { + cmd.Dir = filepath.Dir(path) + } cmd.Stdout = &out cmd.Stderr = &stderr // Start command