From deab7b717df3f7ac7acbecc292c3a8d434fa0b3a Mon Sep 17 00:00:00 2001 From: Daniele Conventi Date: Fri, 26 Aug 2016 14:52:27 +0200 Subject: [PATCH 1/9] 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") { From fe78edcda4deccd49d6a156f9aac6c81fdc7974c Mon Sep 17 00:00:00 2001 From: Daniele Conventi Date: Fri, 26 Aug 2016 16:05:43 +0200 Subject: [PATCH 2/9] Removed log --- realize/watcher.go | 1 - 1 file changed, 1 deletion(-) diff --git a/realize/watcher.go b/realize/watcher.go index 4006706..a962dea 100644 --- a/realize/watcher.go +++ b/realize/watcher.go @@ -41,7 +41,6 @@ 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") { From f95bbbe537e682977e5c31aa713218a6a96eea59 Mon Sep 17 00:00:00 2001 From: Daniele Conventi Date: Fri, 26 Aug 2016 19:33:13 +0200 Subject: [PATCH 3/9] Specified new custom params feature --- README.md | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 49d0d8f..71a5bc0 100644 --- a/README.md +++ b/README.md @@ -93,6 +93,13 @@ A Go build system with file watchers, output streams and live reload. Run, build $ realize fast ``` + If you want you can specify command flags and parameters + + ``` + $ realize fast --flag1 param1 + ``` + + The fast command supports the following custom parameters: ``` @@ -106,7 +113,7 @@ A Go build system with file watchers, output streams and live reload. Run, build #### Color reference - Blue: outputs of the project -- Red: errors +- Red: errors - Magenta: times or changed files - Green: successfully completed action @@ -124,6 +131,9 @@ A Go build system with file watchers, output streams and live reload. Run, build app_bin: true -> enable/disable go install app_build: false -> enable/disable go build app_fmt: true -> enable/disable go fmt + app_params: + - --flag1 + - param1 app_watcher: preview: true -> prints the observed files on startup paths: -> paths to observe for live reload @@ -170,7 +180,7 @@ A Go build system with file watchers, output streams and live reload. Run, build - [ ] Test under windows - [ ] Unit test - [ ] Custom path on commands -- [ ] Output files +- [ ] Output files - [ ] Cli args - [ ] Before/After command From 7d68650706c8f5f455cbe7932f808a2558c1b2f9 Mon Sep 17 00:00:00 2001 From: alessio Date: Sat, 27 Aug 2016 15:07:00 +0200 Subject: [PATCH 4/9] params support fixed --- main.go | 6 ---- realize/config.go | 77 +++++++++++++++++++++++++++------------------- realize/project.go | 18 +++++------ 3 files changed, 55 insertions(+), 46 deletions(-) diff --git a/main.go b/main.go index c18b57c..2a529c1 100644 --- a/main.go +++ b/main.go @@ -69,12 +69,6 @@ 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/config.go b/realize/config.go index 47b0125..5af7c4a 100644 --- a/realize/config.go +++ b/realize/config.go @@ -19,8 +19,45 @@ type Config struct { Projects []Project } +// New method puts the cli params in the struct +func New(params *cli.Context) *Config { + return &Config{ + file: AppFile, + Version: AppVersion, + Projects: []Project{ + { + Name: nameFlag(params), + Path: filepath.Clean(params.String("path")), + Build: params.Bool("build"), + Bin: boolFlag(params.Bool("no-bin")), + Run: boolFlag(params.Bool("no-run")), + Fmt: boolFlag(params.Bool("no-fmt")), + Params: argsParam(params), + Watcher: Watcher{ + Paths: watcherPaths, + Ignore: watcherIgnores, + Exts: watcherExts, + }, + }, + }, + } +} + +// argsParam parse one by one the given argumentes +func argsParam(params *cli.Context) []string { + argsN := params.NArg() + if argsN > 0 { + var args []string + for i := 0; i <= argsN-1; i++ { + args = append(args, params.Args().Get(i)) + } + return args + } + return nil +} + // NameParam check the project name presence. If empty takes the working directory name -func nameParam(params *cli.Context) string { +func nameFlag(params *cli.Context) string { var name string if params.String("name") == "" && params.String("path") == "" { return WorkingDir() @@ -33,7 +70,7 @@ func nameParam(params *cli.Context) string { } // BoolParam is used to check the presence of a bool flag -func boolParam(b bool) bool { +func boolFlag(b bool) bool { if b { return false } @@ -49,29 +86,6 @@ func WorkingDir() string { return filepath.Base(dir) } -// New method puts the cli params in the struct -func New(params *cli.Context) *Config { - return &Config{ - file: AppFile, - Version: AppVersion, - Projects: []Project{ - { - Name: nameParam(params), - Path: filepath.Clean(params.String("path")), - Build: params.Bool("build"), - Bin: boolParam(params.Bool("no-bin")), - Run: boolParam(params.Bool("no-run")), - Fmt: boolParam(params.Bool("no-fmt")), - Watcher: Watcher{ - Paths: watcherPaths, - Ignore: watcherIgnores, - Exts: watcherExts, - }, - }, - }, - } -} - // Duplicates check projects with same name or same combinations of main/path func Duplicates(value Project, arr []Project) (error, Project) { for _, val := range arr { @@ -127,12 +141,13 @@ func (h *Config) Add(params *cli.Context) error { err := h.Read() if err == nil { new := Project{ - Name: nameParam(params), - Path: filepath.Clean(params.String("path")), - Build: params.Bool("build"), - Bin: boolParam(params.Bool("no-bin")), - Run: boolParam(params.Bool("no-run")), - Fmt: boolParam(params.Bool("no-fmt")), + Name: nameFlag(params), + Path: filepath.Clean(params.String("path")), + Build: params.Bool("build"), + Bin: boolFlag(params.Bool("no-bin")), + Run: boolFlag(params.Bool("no-run")), + Fmt: boolFlag(params.Bool("no-fmt")), + Params: argsParam(params), Watcher: Watcher{ Paths: watcherPaths, Exts: watcherExts, diff --git a/realize/project.go b/realize/project.go index 18fa13e..43461c2 100644 --- a/realize/project.go +++ b/realize/project.go @@ -16,14 +16,14 @@ 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"` - Params []string `yaml:"app_params,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 @@ -33,7 +33,7 @@ func (p *Project) GoRun(channel chan bool, runner chan bool, wr *sync.WaitGroup) var build *exec.Cmd if len(p.Params) != 0 { build = exec.Command(filepath.Join(os.Getenv("GOBIN"), filepath.Base(p.Path)), p.Params...) - } else{ + } else { build = exec.Command(filepath.Join(os.Getenv("GOBIN"), filepath.Base(p.Path))) } build.Dir = p.base From 384362fa3deb11e1c2b2ee0031a048bc794452f3 Mon Sep 17 00:00:00 2001 From: alessio Date: Sat, 27 Aug 2016 15:11:21 +0200 Subject: [PATCH 5/9] params added to the list --- realize/config.go | 1 + 1 file changed, 1 insertion(+) diff --git a/realize/config.go b/realize/config.go index 5af7c4a..3166037 100644 --- a/realize/config.go +++ b/realize/config.go @@ -201,6 +201,7 @@ func (h *Config) List() error { fmt.Println(MagentaS("|"), "\t", Yellow("Build"), ":", MagentaS(val.Build)) fmt.Println(MagentaS("|"), "\t", Yellow("Install"), ":", MagentaS(val.Bin)) fmt.Println(MagentaS("|"), "\t", Yellow("Fmt"), ":", MagentaS(val.Fmt)) + fmt.Println(MagentaS("|"), "\t", Yellow("Params"), ":", MagentaS(val.Params)) fmt.Println(MagentaS("|"), "\t", Yellow("Watcher"), ":") fmt.Println(MagentaS("|"), "\t\t", Yellow("After"), ":", MagentaS(val.Watcher.After)) fmt.Println(MagentaS("|"), "\t\t", Yellow("Before"), ":", MagentaS(val.Watcher.Before)) From 3493b1b3f45b2c350b004aa9de8b62b79960a977 Mon Sep 17 00:00:00 2001 From: alessio Date: Sat, 27 Aug 2016 15:21:12 +0200 Subject: [PATCH 6/9] test moved to milestone 1.1 --- realize/config_test.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/realize/config_test.go b/realize/config_test.go index 1a9cb1f..222cff1 100644 --- a/realize/config_test.go +++ b/realize/config_test.go @@ -7,10 +7,10 @@ import ( var context *cli.Context -func TestNew(t *testing.T) { - actual := New(context) - expected := &Config{file: AppFile, Version: AppVersion} - if actual == expected { - t.Errorf("Test failed, expected: '%s', got: '%s'", expected, actual) - } -} +//func TestNew(t *testing.T) { +// actual := New(context) +// expected := &Config{file: AppFile, Version: AppVersion} +// if actual == expected { +// t.Errorf("Test failed, expected: '%s', got: '%s'", expected, actual) +// } +//} From 25eaf8477573495580a239cfd79abf9511b4c8eb Mon Sep 17 00:00:00 2001 From: alessio Date: Sat, 27 Aug 2016 15:53:03 +0200 Subject: [PATCH 7/9] test moved to milestone 1.1 --- realize/config_test.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/realize/config_test.go b/realize/config_test.go index 222cff1..1c32851 100644 --- a/realize/config_test.go +++ b/realize/config_test.go @@ -1,11 +1,11 @@ package realize -import ( - "gopkg.in/urfave/cli.v2" - "testing" -) - -var context *cli.Context +//import ( +// "gopkg.in/urfave/cli.v2" +// "testing" +//) +// +//var context *cli.Context //func TestNew(t *testing.T) { // actual := New(context) From 8aca7e8d378684fb86cc25c1c87e2a90586c08fa Mon Sep 17 00:00:00 2001 From: alessio Date: Sat, 27 Aug 2016 15:55:42 +0200 Subject: [PATCH 8/9] test moved to milestone 1.1 --- realize/config_test.go | 16 ---------------- 1 file changed, 16 deletions(-) delete mode 100644 realize/config_test.go diff --git a/realize/config_test.go b/realize/config_test.go deleted file mode 100644 index 1c32851..0000000 --- a/realize/config_test.go +++ /dev/null @@ -1,16 +0,0 @@ -package realize - -//import ( -// "gopkg.in/urfave/cli.v2" -// "testing" -//) -// -//var context *cli.Context - -//func TestNew(t *testing.T) { -// actual := New(context) -// expected := &Config{file: AppFile, Version: AppVersion} -// if actual == expected { -// t.Errorf("Test failed, expected: '%s', got: '%s'", expected, actual) -// } -//} From f4a5d71109a3398fbb4cf2e9852b388d9f097a6a Mon Sep 17 00:00:00 2001 From: alessio Date: Sat, 27 Aug 2016 16:55:29 +0200 Subject: [PATCH 9/9] additional arguments doc --- README.md | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 71a5bc0..cb25d7f 100644 --- a/README.md +++ b/README.md @@ -71,6 +71,16 @@ A Go build system with file watchers, output streams and live reload. Run, build ``` $ realize add --name="My Project" --path="projects/package" --build --no-run ``` + + If you want, you can specify additional arguments for your project. + **The additional arguments must go after the options of "Realize"** + + ``` + $ realize add --path="/print/printer" --no-run yourParams --yourFlags // correct + + $ realize add yourParams --yourFlags --path="/print/printer" --no-run // wrong + ``` + - Remove a project by its name ``` @@ -92,15 +102,8 @@ A Go build system with file watchers, output streams and live reload. Run, build ``` $ realize fast ``` - - If you want you can specify command flags and parameters - - ``` - $ realize fast --flag1 param1 - ``` - - - The fast command supports the following custom parameters: + + The fast command supports the following custom parameters: ``` --build -> Enables the build @@ -108,7 +111,16 @@ A Go build system with file watchers, output streams and live reload. Run, build --no-run -> Disables the run --no-fmt -> Disables the fmt (go fmt) --config -> Take the defined settings if exist a config file - ``` + ``` + + The "fast" command supporst addittional arguments as the "add" command. + + ``` + $ realize fast --no-run yourParams --yourFlags // correct + + $ realize fast yourParams --yourFlags --no-run // wrong + ``` + #### Color reference @@ -168,6 +180,7 @@ A Go build system with file watchers, output streams and live reload. Run, build - [x] Watcher files preview - [x] Support for directories with duplicates names - [ ] Go test support +- [x] Additional arguments - [x] Go fmt support - [x] Cli fast run - [x] Execution times for build/install