diff --git a/watcher/cmd.go b/watcher/cmd.go index a41b4f2..703d64f 100644 --- a/watcher/cmd.go +++ b/watcher/cmd.go @@ -25,27 +25,27 @@ func (h *Blueprint) Run(p *cli.Context) error { if p.String("name") != "" && h.Projects[k].Name != p.String("name") { continue } - if element.Cmds.Fmt { + if element.Cmds.Fmt.Status { h.Projects[k].tools.Fmt = tool{ - status: &h.Projects[k].Cmds.Fmt, + status: &h.Projects[k].Cmds.Fmt.Status, cmd: "gofmt", - options: []string{"-s", "-w", "-e"}, + options: arguments([]string{}, element.Cmds.Fmt.Args), name: "Go Fmt", } } - if element.Cmds.Generate { + if element.Cmds.Generate.Status { h.Projects[k].tools.Generate = tool{ - status: &h.Projects[k].Cmds.Generate, + status: &h.Projects[k].Cmds.Generate.Status, cmd: "go", - options: []string{"generate"}, + options: arguments([]string{"generate"}, element.Cmds.Generate.Args), name: "Go Generate", } } - if element.Cmds.Test { + if element.Cmds.Test.Status { h.Projects[k].tools.Test = tool{ - status: &h.Projects[k].Cmds.Test, + status: &h.Projects[k].Cmds.Test.Status, cmd: "go", - options: []string{"test"}, + options: arguments([]string{"test"}, element.Cmds.Test.Args), name: "Go Test", } } @@ -58,6 +58,7 @@ func (h *Blueprint) Run(p *cli.Context) error { } } h.Projects[k].parent = h + h.Projects[k].Settings = *h.Settings h.Projects[k].path = h.Projects[k].Path // env variables @@ -81,7 +82,7 @@ func (h *Blueprint) Run(p *cli.Context) error { h.Projects[k].base = filepath.Join(wd, element.path) } - if h.Legacy.Status { + if h.Legacy.Interval != 0 { go h.Projects[k].watchByPolling() } else { go h.Projects[k].watchByNotify() @@ -99,10 +100,16 @@ func (h *Blueprint) Add(p *cli.Context) error { Name: h.Name(p.String("name"), p.String("path")), Path: h.Path(p.String("path")), Cmds: Cmds{ - Vet: p.Bool("vet"), - Fmt: !p.Bool("no-fmt"), - Test: p.Bool("test"), - Generate: p.Bool("generate"), + Vet: p.Bool("vet"), + Fmt: Cmd{ + Status: !p.Bool("no-fmt"), + }, + Test: Cmd{ + Status: !p.Bool("test"), + }, + Generate: Cmd{ + Status: !p.Bool("generate"), + }, Build: Cmd{ Status: p.Bool("build"), }, diff --git a/watcher/exec.go b/watcher/exec.go index df8339f..4bf7114 100644 --- a/watcher/exec.go +++ b/watcher/exec.go @@ -114,10 +114,7 @@ func (p *Project) goBuild() (string, error) { var out bytes.Buffer var stderr bytes.Buffer args := []string{"build"} - for _, arg := range p.Cmds.Build.Args { - arr := strings.Fields(arg) - args = append(args, arr...) - } + args = arguments(args, p.Cmds.Build.Args) build := exec.Command("go", args...) build.Dir = p.base build.Stdout = &out diff --git a/watcher/main.go b/watcher/main.go index 2ae9b47..2db3014 100644 --- a/watcher/main.go +++ b/watcher/main.go @@ -61,9 +61,9 @@ type tool struct { // Cmds go supported type Cmds struct { Vet bool `yaml:"vet,omitempty" json:"vet,omitempty"` - Fmt bool `yaml:"fmt,omitempty" json:"fmt,omitempty"` - Test bool `yaml:"test,omitempty" json:"test,omitempty"` - Generate bool `yaml:"generate,omitempty" json:"generate,omitempty"` + Fmt Cmd `yaml:"fmt,omitempty" json:"fmt,omitempty"` + Test Cmd `yaml:"test,omitempty" json:"test,omitempty"` + Generate Cmd `yaml:"generate,omitempty" json:"generate,omitempty"` Bin Cmd `yaml:"bin" json:"bin"` Build Cmd `yaml:"build,omitempty" json:"build,omitempty"` Run bool `yaml:"run,omitempty" json:"run,omitempty"` @@ -90,6 +90,7 @@ type Command struct { Command string `yaml:"command" json:"command"` Path string `yaml:"path,omitempty" json:"path,omitempty"` Global bool `yaml:"global,omitempty" json:"global,omitempty"` + Output bool `yaml:"output,omitempty" json:"output,omitempty"` } // Buffer define an array buffer for each log files diff --git a/watcher/utils.go b/watcher/utils.go index 7a79c52..10e273b 100644 --- a/watcher/utils.go +++ b/watcher/utils.go @@ -9,6 +9,7 @@ import ( "github.com/tockins/realize/style" cli "gopkg.in/urfave/cli.v2" + "strings" ) // Argsparam parse one by one the given argumentes @@ -57,3 +58,12 @@ func getEnvPath(env string) string { } return path[0] } + +// Split each arguments in multiple fields +func arguments(args, fields []string) []string { + for _, arg := range fields { + arr := strings.Fields(arg) + args = append(args, arr...) + } + return args +} diff --git a/watcher/watcher.go b/watcher/watcher.go index a936522..dd471e3 100644 --- a/watcher/watcher.go +++ b/watcher/watcher.go @@ -290,7 +290,7 @@ func (p *Project) cmd(flag string, global bool) { } else { p.stamp("log", out, msg, "") } - if logs != "" { + if logs != "" && cmd.Output { msg = fmt.Sprintln(logs) out = BufferOut{Time: time.Now(), Text: logs, Type: flag} p.stamp("log", out, "", msg) @@ -316,8 +316,8 @@ func (p *Project) ignore(str string) bool { // Routines launches the toolchain run, build, install func (p *Project) routines(wr *sync.WaitGroup, channel chan bool, watcher watcher, file string) { + p.cmd("before", false) if len(file) > 0 { - p.cmd("before", false) path := filepath.Dir(file) p.tool(file, p.tools.Fmt) p.tool(path, p.tools.Vet) @@ -336,7 +336,6 @@ func (p *Project) routines(wr *sync.WaitGroup, channel chan bool, watcher watche if len(file) > 0 { p.cmd("after", false) } - } // Defines the colors scheme for the project name @@ -366,8 +365,8 @@ func (p *Project) stamp(t string, o BufferOut, msg string, stream string) { switch t { case "out": p.Buffer.StdOut = append(p.Buffer.StdOut, o) - if p.Resources.Outputs.Status { - f := p.Create(p.base, p.Resources.Outputs.Name) + if p.Files.Outputs.Status { + f := p.Create(p.base, p.Files.Outputs.Name) t := time.Now() s := []string{t.Format("2006-01-02 15:04:05"), strings.ToUpper(p.Name), ":", o.Text, "\r\n"} if _, err := f.WriteString(strings.Join(s, " ")); err != nil { @@ -376,8 +375,8 @@ func (p *Project) stamp(t string, o BufferOut, msg string, stream string) { } case "log": p.Buffer.StdLog = append(p.Buffer.StdLog, o) - if p.Resources.Logs.Status { - f := p.Create(p.base, p.Resources.Logs.Name) + if p.Files.Logs.Status { + f := p.Create(p.base, p.Files.Logs.Name) t := time.Now() s := []string{t.Format("2006-01-02 15:04:05"), strings.ToUpper(p.Name), ":", o.Text, "\r\n"} if stream != "" { @@ -389,8 +388,8 @@ func (p *Project) stamp(t string, o BufferOut, msg string, stream string) { } case "error": p.Buffer.StdErr = append(p.Buffer.StdErr, o) - if p.Resources.Errors.Status { - f := p.Create(p.base, p.Resources.Errors.Name) + if p.Files.Errors.Status { + f := p.Create(p.base, p.Files.Errors.Name) t := time.Now() s := []string{t.Format("2006-01-02 15:04:05"), strings.ToUpper(p.Name), ":", o.Type, o.Text, o.Path, "\r\n"} if stream != "" {