From 5f1a5c98589eb4ed22c1c2afc181fbc24e944dae Mon Sep 17 00:00:00 2001 From: asoseil Date: Mon, 20 Nov 2017 14:17:01 +0100 Subject: [PATCH] minor bug fixes --- cli.go | 22 ++++++++-------------- projects.go | 11 ++++++----- realize.go | 14 ++++++++------ schema.go | 1 - 4 files changed, 22 insertions(+), 26 deletions(-) diff --git a/cli.go b/cli.go index 6dc7d40..31a12f8 100644 --- a/cli.go +++ b/cli.go @@ -13,14 +13,12 @@ import ( ) // Version print current version -func version() { - r := Realize{} - log.Println(r.Prefix(green.bold(version))) +func (r *Realize) version() { + log.Println(r.Prefix(green.bold(RVersion))) } // Clean remove realize folder -func clean() (err error) { - r := Realize{} +func (r *Realize) clean() (err error) { if err := r.Settings.Remove(RDir); err != nil { return err } @@ -29,8 +27,7 @@ func clean() (err error) { } // Add a project to an existing config or create a new one -func add(c *cli.Context) (err error) { - r := Realize{} +func (r *Realize) add(c *cli.Context) (err error) { // read a config if exist err = r.Settings.Read(&r) if err != nil { @@ -53,8 +50,7 @@ func add(c *cli.Context) (err error) { } // Setup a new config step by step -func setup(c *cli.Context) (err error) { - r := Realize{} +func (r *Realize) setup(c *cli.Context) (err error) { interact.Run(&interact.Interact{ Before: func(context interact.Context) error { context.SetErr(red.bold("INVALID INPUT")) @@ -1065,9 +1061,8 @@ func setup(c *cli.Context) (err error) { } // Start realize workflow -func start(c *cli.Context) (err error) { - r := Realize{} - r.Server = Server{&r, false, false, Port, Host} +func (r *Realize) start(c *cli.Context) (err error) { + r.Server = Server{r, false, false, Port, Host} // check no-config and read if !c.Bool("no-config") { // read a config if exist @@ -1119,8 +1114,7 @@ func start(c *cli.Context) (err error) { } // Remove a project from an existing config -func remove(c *cli.Context) (err error) { - r := Realize{} +func (r *Realize) remove(c *cli.Context) (err error) { // read a config if exist err = r.Settings.Read(&r) if err != nil { diff --git a/projects.go b/projects.go index 358972b..dbee885 100644 --- a/projects.go +++ b/projects.go @@ -85,6 +85,7 @@ func (p *Project) Setup() { p.Buffer.StdErr = append(p.Buffer.StdErr, BufferOut{Time: time.Now(), Text: err.Error(), Type: "Env error", Stream: ""}) } } + // setup go tools p.Tools.Setup() } @@ -214,7 +215,7 @@ func (p *Project) Reload(watcher FileWatcher, path string, stop <-chan bool) { p.stamp("log", out, msg, "") start := time.Now() install = p.Tools.Install.Compile(p.Path, stop) - install.printAfter(start, p) + install.print(start, p) } if done { return @@ -225,7 +226,7 @@ func (p *Project) Reload(watcher FileWatcher, path string, stop <-chan bool) { p.stamp("log", out, msg, "") start := time.Now() build = p.Tools.Build.Compile(p.Path, stop) - build.printAfter(start, p) + build.print(start, p) } if done { return @@ -256,7 +257,7 @@ func (p *Project) Reload(watcher FileWatcher, path string, stop <-chan bool) { log.Println(p.pname(p.Name, 1), ":", "Running..") start = time.Now() err := p.Run(p.Path, result, stop) - if err != nil{ + if err != nil { msg := fmt.Sprintln(p.pname(p.Name, 2), ":", red.regular(err)) out := BufferOut{Time: time.Now(), Text: err.Error(), Type: "Go Run"} p.stamp("error", out, msg, "") @@ -275,7 +276,7 @@ func (p *Project) Run(path string, stream chan Response, stop <-chan bool) (err var build *exec.Cmd var r Response defer func() { - if e := build.Process.Kill(); e != nil{ + if e := build.Process.Kill(); e != nil { err = e } }() @@ -522,7 +523,7 @@ func (p *Project) stamp(t string, o BufferOut, msg string, stream string) { } // Print with time after -func (r *Response) printAfter(start time.Time, p *Project) { +func (r *Response) print(start time.Time, p *Project) { if r.Err != nil { msg = fmt.Sprintln(p.pname(p.Name, 2), ":", red.bold(r.Name), "\n", r.Err.Error()) out = BufferOut{Time: time.Now(), Text: r.Err.Error(), Type: r.Name, Stream: r.Out} diff --git a/realize.go b/realize.go index 21c45d0..98caf72 100644 --- a/realize.go +++ b/realize.go @@ -33,6 +33,8 @@ type ( LogWriter struct{} ) +var r Realize + // init check func init() { // custom log @@ -71,7 +73,7 @@ func main() { &cli.BoolFlag{Name: "no-config", Aliases: []string{"nc"}, Value: false, Usage: "Ignore existing config and doesn't create a new one"}, }, Action: func(c *cli.Context) error { - return start(c) + return r.start(c) }, }, { @@ -90,7 +92,7 @@ func main() { &cli.BoolFlag{Name: "run", Aliases: []string{"nr"}, Value: false, Usage: "Enable go run"}, }, Action: func(c *cli.Context) error { - return add(c) + return r.add(c) }, }, { @@ -99,7 +101,7 @@ func main() { Aliases: []string{"i"}, Description: "Make a new config file step by step.", Action: func(c *cli.Context) error { - return setup(c) + return r.setup(c) }, }, { @@ -111,7 +113,7 @@ func main() { &cli.StringFlag{Name: "name", Aliases: []string{"n"}, Value: ""}, }, Action: func(c *cli.Context) error { - return remove(c) + return r.remove(c) }, }, { @@ -120,7 +122,7 @@ func main() { Aliases: []string{"c"}, Description: "Remove " + strings.Title(RPrefix) + " folder.", Action: func(c *cli.Context) error { - return clean() + return r.clean() }, }, { @@ -128,7 +130,7 @@ func main() { Aliases: []string{"v"}, Description: "Print " + strings.Title(RPrefix) + " version.", Action: func(p *cli.Context) error { - version() + r.version() return nil }, }, diff --git a/schema.go b/schema.go index b298489..0abe5f2 100644 --- a/schema.go +++ b/schema.go @@ -5,7 +5,6 @@ import ( "gopkg.in/urfave/cli.v2" "path/filepath" "reflect" - "fmt" ) // Schema projects list