This commit is contained in:
asoseil 2017-11-20 18:33:24 +01:00
parent ab2c873d08
commit 74366bfada
3 changed files with 28 additions and 14 deletions

View File

@ -75,11 +75,11 @@ type BufferOut struct {
Errors []string `json:"errors"` Errors []string `json:"errors"`
} }
type ProjectI interface{ type ProjectI interface {
Setup() Setup()
Watch(chan os.Signal) Watch(chan os.Signal)
Run(string, chan Response,<-chan bool) Run(string, chan Response, <-chan bool)
Restart(FileWatcher,string,<-chan bool) Restart(FileWatcher, string, <-chan bool)
} }
// Setup a project // Setup a project
@ -210,7 +210,7 @@ func (p *Project) Restart(watcher FileWatcher, path string, stop <-chan bool) {
// Prevent fake events on polling startup // Prevent fake events on polling startup
p.init = true p.init = true
// prevent errors using realize without config with only run flag // 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 p.Tools.Install.Status = true
} }
if done { if done {
@ -238,7 +238,7 @@ func (p *Project) Restart(watcher FileWatcher, path string, stop <-chan bool) {
if done { if done {
return 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 var start time.Time
result := make(chan Response) result := make(chan Response)
go func() { go func() {
@ -309,12 +309,15 @@ func (p *Project) Run(path string, stream chan Response, stop <-chan bool) (err
}) })
args = append(args, a...) args = append(args, a...)
} }
gobin := os.Getenv("GOBIN") dirPath := os.Getenv("GOBIN")
dirPath := filepath.Base(path) if p.Tools.Run.Dir != "" {
if path == "." { dirPath, _ = filepath.Abs(p.Tools.Run.Dir)
dirPath = filepath.Base(Wdir())
} }
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 { if _, err := os.Stat(path); err == nil {
build = exec.Command(path, args...) build = exec.Command(path, args...)
} else if _, err := os.Stat(path + RExtWin); err == nil { } else if _, err := os.Stat(path + RExtWin); err == nil {

View File

@ -61,7 +61,9 @@ func (s *Schema) New(c *cli.Context) Project {
Install: Tool{ Install: Tool{
Status: c.Bool("install"), Status: c.Bool("install"),
}, },
Run: c.Bool("run"), Run: Tool{
Status: c.Bool("run"),
},
}, },
Args: params(c), Args: params(c),
Watcher: Watch{ Watcher: Watch{

View File

@ -12,6 +12,7 @@ import (
type Tool struct { type Tool struct {
Args []string `yaml:"args,omitempty" json:"args,omitempty"` Args []string `yaml:"args,omitempty" json:"args,omitempty"`
Method string `yaml:"method,omitempty" json:"method,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"` Status bool `yaml:"status,omitempty" json:"status,omitempty"`
dir bool dir bool
isTool bool isTool bool
@ -30,7 +31,7 @@ type Tools struct {
Generate Tool `yaml:"generate,omitempty" json:"generate,omitempty"` Generate Tool `yaml:"generate,omitempty" json:"generate,omitempty"`
Install Tool `yaml:"install,omitempty" json:"install,omitempty"` Install Tool `yaml:"install,omitempty" json:"install,omitempty"`
Build Tool `yaml:"build,omitempty" json:"build,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 // Setup go tools
@ -111,7 +112,11 @@ func (t *Tool) Exec(path string, stop <-chan bool) (response Response) {
done := make(chan error) done := make(chan error)
args = append(t.cmd, t.Args...) args = append(t.cmd, t.Args...)
cmd := exec.Command(args[0], args[1:]...) 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.Stdout = &out
cmd.Stderr = &stderr cmd.Stderr = &stderr
// Start command // Start command
@ -143,7 +148,11 @@ func (t *Tool) Compile(path string, stop <-chan bool) (response Response) {
done := make(chan error) done := make(chan error)
args := append(t.cmd, t.Args...) args := append(t.cmd, t.Args...)
cmd := exec.Command(args[0], args[1:]...) 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.Stdout = &out
cmd.Stderr = &stderr cmd.Stderr = &stderr
// Start command // Start command