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"`
}
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 {

View File

@ -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{

View File

@ -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