From deab7b717df3f7ac7acbecc292c3a8d434fa0b3a Mon Sep 17 00:00:00 2001 From: Daniele Conventi Date: Fri, 26 Aug 2016 14:52:27 +0200 Subject: [PATCH] Initial custom args support --- main.go | 6 ++++++ realize/project.go | 22 ++++++++++++++-------- realize/watcher.go | 1 + 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/main.go b/main.go index 2a529c1..c18b57c 100644 --- a/main.go +++ b/main.go @@ -69,6 +69,12 @@ func main() { }, Action: func(p *cli.Context) error { y := r.New(p) + if p.NArg() > 0 { + y.Projects[0].Params = make([]string, p.NArg() - 1) + for i := 1; i < p.NArg(); i++ { + y.Projects[0].Params[i - 1] = p.Args().Get(i) + } + } return handle(y.Fast(p)) }, Before: func(c *cli.Context) error { diff --git a/realize/project.go b/realize/project.go index 94b4ef3..18fa13e 100644 --- a/realize/project.go +++ b/realize/project.go @@ -16,20 +16,26 @@ import ( type Project struct { reload time.Time base string - Name string `yaml:"app_name,omitempty"` - Path string `yaml:"app_path,omitempty"` - Run bool `yaml:"app_run,omitempty"` - Bin bool `yaml:"app_bin,omitempty"` - Build bool `yaml:"app_build,omitempty"` - Fmt bool `yaml:"app_fmt,omitempty"` - Watcher Watcher `yaml:"app_watcher,omitempty"` + Name string `yaml:"app_name,omitempty"` + Path string `yaml:"app_path,omitempty"` + Run bool `yaml:"app_run,omitempty"` + Bin bool `yaml:"app_bin,omitempty"` + Build bool `yaml:"app_build,omitempty"` + Fmt bool `yaml:"app_fmt,omitempty"` + Params []string `yaml:"app_params,omitempty"` + Watcher Watcher `yaml:"app_watcher,omitempty"` } // GoRun is an implementation of the bin execution func (p *Project) GoRun(channel chan bool, runner chan bool, wr *sync.WaitGroup) error { stop := make(chan bool, 1) - build := exec.Command(filepath.Join(os.Getenv("GOBIN"), filepath.Base(p.Path))) + var build *exec.Cmd + if len(p.Params) != 0 { + build = exec.Command(filepath.Join(os.Getenv("GOBIN"), filepath.Base(p.Path)), p.Params...) + } else{ + build = exec.Command(filepath.Join(os.Getenv("GOBIN"), filepath.Base(p.Path))) + } build.Dir = p.base defer func() { if err := build.Process.Kill(); err != nil { diff --git a/realize/watcher.go b/realize/watcher.go index a962dea..4006706 100644 --- a/realize/watcher.go +++ b/realize/watcher.go @@ -41,6 +41,7 @@ func (h *Config) Watch() error { // Fast method run a project from his working directory without makes a config file func (h *Config) Fast(params *cli.Context) error { + log.Println(h.Projects[0]) fast := h.Projects[0] // Takes the values from config if wd path match with someone else if params.Bool("config") {