diff --git a/README.md b/README.md index 49d0d8f..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,8 +102,8 @@ A Go build system with file watchers, output streams and live reload. Run, build ``` $ realize fast ``` - - The fast command supports the following custom parameters: + + The fast command supports the following custom parameters: ``` --build -> Enables the build @@ -101,12 +111,21 @@ 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 - Blue: outputs of the project -- Red: errors +- Red: errors - Magenta: times or changed files - Green: successfully completed action @@ -124,6 +143,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 @@ -158,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 @@ -170,7 +193,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 diff --git a/realize/config.go b/realize/config.go index 47b0125..3166037 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, @@ -186,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)) diff --git a/realize/config_test.go b/realize/config_test.go deleted file mode 100644 index 1a9cb1f..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) - } -} diff --git a/realize/project.go b/realize/project.go index 94b4ef3..43461c2 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 {