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
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 {

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: ""})
}
}
// 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
@ -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}

View File

@ -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
},
},

View File

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