From b7c50a2efba8b9479a7c10c189e83ea97b72d77b Mon Sep 17 00:00:00 2001 From: alessio Date: Thu, 27 Jul 2017 20:48:16 +0200 Subject: [PATCH] code review --- realize.go | 16 ++++++++-------- settings/settings.go | 2 +- watcher/cmd.go | 8 ++++---- watcher/watcher.go | 6 +++--- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/realize.go b/realize.go index dfcd376..46c2de1 100644 --- a/realize.go +++ b/realize.go @@ -122,25 +122,25 @@ func main() { }, Action: func(p *cli.Context) error { c := r - if p.String("name") != ""{ - for index, project := range r.Blueprint.Projects{ - if project.Name == p.String("name"){ + if p.String("name") != "" { + for index, project := range r.Blueprint.Projects { + if project.Name == p.String("name") { c.Blueprint.Projects = []watcher.Project{r.Blueprint.Projects[index]} } } } if p.Bool("legacy") { - r.Config.Legacy = settings.Legacy{ + c.Config.Legacy = settings.Legacy{ Status: p.Bool("legacy"), Interval: interval, } } - if p.Bool("no-config") || len(r.Blueprint.Projects) <= 0 { + if p.Bool("no-config") || len(c.Blueprint.Projects) <= 0 { if p.Bool("no-config") { - r.Config.Create = false + c.Config.Create = false } - r.Blueprint.Projects = []watcher.Project{} - if err := r.Blueprint.Add(p); err != nil { + c.Blueprint.Projects = []watcher.Project{} + if err := c.Blueprint.Add(p); err != nil { return err } } diff --git a/settings/settings.go b/settings/settings.go index 21e56ae..450b5c1 100644 --- a/settings/settings.go +++ b/settings/settings.go @@ -1,9 +1,9 @@ package settings import ( + yaml "gopkg.in/yaml.v2" "os" "time" - yaml "gopkg.in/yaml.v2" ) var Dir = ".realize/" diff --git a/watcher/cmd.go b/watcher/cmd.go index 8e367aa..84b96a2 100644 --- a/watcher/cmd.go +++ b/watcher/cmd.go @@ -16,7 +16,7 @@ func (h *Blueprint) Run(p *cli.Context) error { wg.Add(len(h.Projects)) for k, element := range h.Projects { tools := tools{} - if element.Cmds.Fmt{ + if element.Cmds.Fmt { tools.Fmt = tool{ status: &h.Projects[k].Cmds.Fmt, cmd: "gofmt", @@ -24,7 +24,7 @@ func (h *Blueprint) Run(p *cli.Context) error { name: "Go Fmt", } } - if element.Cmds.Generate{ + if element.Cmds.Generate { tools.Generate = tool{ status: &h.Projects[k].Cmds.Generate, cmd: "go", @@ -32,7 +32,7 @@ func (h *Blueprint) Run(p *cli.Context) error { name: "Go Generate", } } - if element.Cmds.Test{ + if element.Cmds.Test { tools.Test = tool{ status: &h.Projects[k].Cmds.Test, cmd: "go", @@ -178,5 +178,5 @@ func (h *Blueprint) check() error { h.Clean() return nil } - return errors.New("there are no projects") + return errors.New("There are no projects") } diff --git a/watcher/watcher.go b/watcher/watcher.go index 259a6e4..7c7276d 100644 --- a/watcher/watcher.go +++ b/watcher/watcher.go @@ -286,10 +286,10 @@ func (p *Project) tool(path string, tool tool) error { // Cmd calls an wrapper for execute the commands after/before func (p *Project) cmd(flag string, changed bool) { for _, cmd := range p.Watcher.Scripts { - if strings.ToLower(cmd.Type) == flag{ + if strings.ToLower(cmd.Type) == flag { if changed && cmd.Changed || !changed && cmd.Startup { errors, logs := p.command(cmd) - msg = fmt.Sprintln(p.pname(p.Name, 5), ":", style.Green.Bold("Command"), style.Green.Bold("\"") + cmd.Command + style.Green.Bold("\"")) + msg = fmt.Sprintln(p.pname(p.Name, 5), ":", style.Green.Bold("Command"), style.Green.Bold("\"")+cmd.Command+style.Green.Bold("\"")) out = BufferOut{Time: time.Now(), Text: cmd.Command, Type: flag} if logs != "" { p.print("log", out, msg, "") @@ -323,7 +323,7 @@ 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) { +func (p *Project) routines(wr *sync.WaitGroup, channel chan bool, watcher watcher, file string) { if len(file) > 0 { p.cmd("before", true) path := filepath.Dir(file)