minor bug fixes

This commit is contained in:
asoseil 2017-11-20 14:17:01 +01:00
parent 560b623383
commit 5f1a5c9858
4 changed files with 22 additions and 26 deletions

22
cli.go
View File

@ -13,14 +13,12 @@ import (
) )
// Version print current version // Version print current version
func version() { func (r *Realize) version() {
r := Realize{} log.Println(r.Prefix(green.bold(RVersion)))
log.Println(r.Prefix(green.bold(version)))
} }
// Clean remove realize folder // Clean remove realize folder
func clean() (err error) { func (r *Realize) clean() (err error) {
r := Realize{}
if err := r.Settings.Remove(RDir); err != nil { if err := r.Settings.Remove(RDir); err != nil {
return err return err
} }
@ -29,8 +27,7 @@ func clean() (err error) {
} }
// Add a project to an existing config or create a new one // Add a project to an existing config or create a new one
func add(c *cli.Context) (err error) { func (r *Realize) add(c *cli.Context) (err error) {
r := Realize{}
// read a config if exist // read a config if exist
err = r.Settings.Read(&r) err = r.Settings.Read(&r)
if err != nil { if err != nil {
@ -53,8 +50,7 @@ func add(c *cli.Context) (err error) {
} }
// Setup a new config step by step // Setup a new config step by step
func setup(c *cli.Context) (err error) { func (r *Realize) setup(c *cli.Context) (err error) {
r := Realize{}
interact.Run(&interact.Interact{ interact.Run(&interact.Interact{
Before: func(context interact.Context) error { Before: func(context interact.Context) error {
context.SetErr(red.bold("INVALID INPUT")) context.SetErr(red.bold("INVALID INPUT"))
@ -1065,9 +1061,8 @@ func setup(c *cli.Context) (err error) {
} }
// Start realize workflow // Start realize workflow
func start(c *cli.Context) (err error) { func (r *Realize) start(c *cli.Context) (err error) {
r := Realize{} r.Server = Server{r, false, false, Port, Host}
r.Server = Server{&r, false, false, Port, Host}
// check no-config and read // check no-config and read
if !c.Bool("no-config") { if !c.Bool("no-config") {
// read a config if exist // read a config if exist
@ -1119,8 +1114,7 @@ func start(c *cli.Context) (err error) {
} }
// Remove a project from an existing config // Remove a project from an existing config
func remove(c *cli.Context) (err error) { func (r *Realize) remove(c *cli.Context) (err error) {
r := Realize{}
// read a config if exist // read a config if exist
err = r.Settings.Read(&r) err = r.Settings.Read(&r)
if err != nil { if err != nil {

View File

@ -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: ""}) p.Buffer.StdErr = append(p.Buffer.StdErr, BufferOut{Time: time.Now(), Text: err.Error(), Type: "Env error", Stream: ""})
} }
} }
// setup go tools
p.Tools.Setup() p.Tools.Setup()
} }
@ -214,7 +215,7 @@ func (p *Project) Reload(watcher FileWatcher, path string, stop <-chan bool) {
p.stamp("log", out, msg, "") p.stamp("log", out, msg, "")
start := time.Now() start := time.Now()
install = p.Tools.Install.Compile(p.Path, stop) install = p.Tools.Install.Compile(p.Path, stop)
install.printAfter(start, p) install.print(start, p)
} }
if done { if done {
return return
@ -225,7 +226,7 @@ func (p *Project) Reload(watcher FileWatcher, path string, stop <-chan bool) {
p.stamp("log", out, msg, "") p.stamp("log", out, msg, "")
start := time.Now() start := time.Now()
build = p.Tools.Build.Compile(p.Path, stop) build = p.Tools.Build.Compile(p.Path, stop)
build.printAfter(start, p) build.print(start, p)
} }
if done { if done {
return return
@ -256,7 +257,7 @@ func (p *Project) Reload(watcher FileWatcher, path string, stop <-chan bool) {
log.Println(p.pname(p.Name, 1), ":", "Running..") log.Println(p.pname(p.Name, 1), ":", "Running..")
start = time.Now() start = time.Now()
err := p.Run(p.Path, result, stop) err := p.Run(p.Path, result, stop)
if err != nil{ if err != nil {
msg := fmt.Sprintln(p.pname(p.Name, 2), ":", red.regular(err)) msg := fmt.Sprintln(p.pname(p.Name, 2), ":", red.regular(err))
out := BufferOut{Time: time.Now(), Text: err.Error(), Type: "Go Run"} out := BufferOut{Time: time.Now(), Text: err.Error(), Type: "Go Run"}
p.stamp("error", out, msg, "") 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 build *exec.Cmd
var r Response var r Response
defer func() { defer func() {
if e := build.Process.Kill(); e != nil{ if e := build.Process.Kill(); e != nil {
err = e err = e
} }
}() }()
@ -522,7 +523,7 @@ func (p *Project) stamp(t string, o BufferOut, msg string, stream string) {
} }
// Print with time after // 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 { if r.Err != nil {
msg = fmt.Sprintln(p.pname(p.Name, 2), ":", red.bold(r.Name), "\n", r.Err.Error()) 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} out = BufferOut{Time: time.Now(), Text: r.Err.Error(), Type: r.Name, Stream: r.Out}

View File

@ -33,6 +33,8 @@ type (
LogWriter struct{} LogWriter struct{}
) )
var r Realize
// init check // init check
func init() { func init() {
// custom log // 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"}, &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 { 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"}, &cli.BoolFlag{Name: "run", Aliases: []string{"nr"}, Value: false, Usage: "Enable go run"},
}, },
Action: func(c *cli.Context) error { Action: func(c *cli.Context) error {
return add(c) return r.add(c)
}, },
}, },
{ {
@ -99,7 +101,7 @@ func main() {
Aliases: []string{"i"}, Aliases: []string{"i"},
Description: "Make a new config file step by step.", Description: "Make a new config file step by step.",
Action: func(c *cli.Context) error { 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: ""}, &cli.StringFlag{Name: "name", Aliases: []string{"n"}, Value: ""},
}, },
Action: func(c *cli.Context) error { Action: func(c *cli.Context) error {
return remove(c) return r.remove(c)
}, },
}, },
{ {
@ -120,7 +122,7 @@ func main() {
Aliases: []string{"c"}, Aliases: []string{"c"},
Description: "Remove " + strings.Title(RPrefix) + " folder.", Description: "Remove " + strings.Title(RPrefix) + " folder.",
Action: func(c *cli.Context) error { Action: func(c *cli.Context) error {
return clean() return r.clean()
}, },
}, },
{ {
@ -128,7 +130,7 @@ func main() {
Aliases: []string{"v"}, Aliases: []string{"v"},
Description: "Print " + strings.Title(RPrefix) + " version.", Description: "Print " + strings.Title(RPrefix) + " version.",
Action: func(p *cli.Context) error { Action: func(p *cli.Context) error {
version() r.version()
return nil return nil
}, },
}, },

View File

@ -5,7 +5,6 @@ import (
"gopkg.in/urfave/cli.v2" "gopkg.in/urfave/cli.v2"
"path/filepath" "path/filepath"
"reflect" "reflect"
"fmt"
) )
// Schema projects list // Schema projects list