bug fix
This commit is contained in:
parent
3b44ec6291
commit
586f3f2fb5
12
cli.go
12
cli.go
|
@ -1093,12 +1093,12 @@ func start(c *cli.Context) (err error) {
|
|||
project := r.Schema.New(c)
|
||||
// Add to projects list
|
||||
r.Schema.Add(project)
|
||||
}
|
||||
// save config
|
||||
if !c.Bool("no-config") {
|
||||
err = r.Settings.Write(r)
|
||||
if err != nil {
|
||||
return err
|
||||
// save config
|
||||
if !c.Bool("no-config") {
|
||||
err = r.Settings.Write(r)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
// config and start server
|
||||
|
|
58
projects.go
58
projects.go
|
@ -234,24 +234,33 @@ func (p *Project) Reload(watcher FileWatcher, path string, stop <-chan bool) {
|
|||
var start time.Time
|
||||
result := make(chan Response)
|
||||
go func() {
|
||||
select {
|
||||
case r := <-result:
|
||||
if r.Err != nil {
|
||||
msg := fmt.Sprintln(p.pname(p.Name, 2), ":", red.regular(r.Err))
|
||||
out := BufferOut{Time: time.Now(), Text: r.Err.Error(), Type: "Go Run"}
|
||||
p.stamp("error", out, msg, "")
|
||||
}
|
||||
if r.Out != "" {
|
||||
msg := fmt.Sprintln(p.pname(p.Name, 3), ":", blue.regular(r.Out))
|
||||
out := BufferOut{Time: time.Now(), Text: r.Out, Type: "Go Run"}
|
||||
p.stamp("out", out, msg, "")
|
||||
for {
|
||||
select {
|
||||
case <-stop:
|
||||
return
|
||||
case r := <-result:
|
||||
if r.Err != nil {
|
||||
msg := fmt.Sprintln(p.pname(p.Name, 2), ":", red.regular(r.Err))
|
||||
out := BufferOut{Time: time.Now(), Text: r.Err.Error(), Type: "Go Run"}
|
||||
p.stamp("error", out, msg, "")
|
||||
}
|
||||
if r.Out != "" {
|
||||
msg := fmt.Sprintln(p.pname(p.Name, 3), ":", blue.regular(r.Out))
|
||||
out := BufferOut{Time: time.Now(), Text: r.Out, Type: "Go Run"}
|
||||
p.stamp("out", out, msg, "")
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
go func() {
|
||||
log.Println(p.pname(p.Name, 1), ":", "Running..")
|
||||
start = time.Now()
|
||||
p.Run(p.Path, stop)
|
||||
err := p.Run(p.Path, result, stop)
|
||||
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, "")
|
||||
}
|
||||
}()
|
||||
}
|
||||
if done {
|
||||
|
@ -261,13 +270,13 @@ func (p *Project) Reload(watcher FileWatcher, path string, stop <-chan bool) {
|
|||
}
|
||||
|
||||
// Run a project
|
||||
func (p *Project) Run(path string, stop <-chan bool) (response chan Response) {
|
||||
func (p *Project) Run(path string, stream chan Response, stop <-chan bool) (err error) {
|
||||
var args []string
|
||||
var build *exec.Cmd
|
||||
var r Response
|
||||
defer func() {
|
||||
if err := build.Process.Kill(); err != nil {
|
||||
r.Err = err
|
||||
if e := build.Process.Kill(); e != nil{
|
||||
err = e
|
||||
}
|
||||
}()
|
||||
|
||||
|
@ -278,8 +287,7 @@ func (p *Project) Run(path string, stop <-chan bool) (response chan Response) {
|
|||
errRegexp, err := regexp.Compile(p.ErrorOutputPattern)
|
||||
if err != nil {
|
||||
r.Err = err
|
||||
response <- r
|
||||
r.Err = nil
|
||||
stream <- r
|
||||
} else {
|
||||
isErrorText = func(t string) bool {
|
||||
return errRegexp.MatchString(t)
|
||||
|
@ -309,20 +317,17 @@ func (p *Project) Run(path string, stop <-chan bool) (response chan Response) {
|
|||
} else if _, err = os.Stat(path + RExtWin); err == nil {
|
||||
build = exec.Command(path+RExtWin, args...)
|
||||
} else {
|
||||
r.Err = errors.New("project not found")
|
||||
return
|
||||
return errors.New("project not found")
|
||||
}
|
||||
}
|
||||
// scan project stream
|
||||
stdout, err := build.StdoutPipe()
|
||||
stderr, err := build.StderrPipe()
|
||||
if err != nil {
|
||||
r.Err = err
|
||||
return
|
||||
return err
|
||||
}
|
||||
if err := build.Start(); err != nil {
|
||||
r.Err = err
|
||||
return
|
||||
return err
|
||||
}
|
||||
execOutput, execError := bufio.NewScanner(stdout), bufio.NewScanner(stderr)
|
||||
stopOutput, stopError := make(chan bool, 1), make(chan bool, 1)
|
||||
|
@ -331,11 +336,11 @@ func (p *Project) Run(path string, stop <-chan bool) (response chan Response) {
|
|||
text := output.Text()
|
||||
if isError && !isErrorText(text) {
|
||||
r.Err = errors.New(text)
|
||||
response <- r
|
||||
stream <- r
|
||||
r.Err = nil
|
||||
} else {
|
||||
r.Out = text
|
||||
response <- r
|
||||
stream <- r
|
||||
r.Out = ""
|
||||
}
|
||||
}
|
||||
|
@ -516,9 +521,10 @@ 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) {
|
||||
if r.Err != nil {
|
||||
msg = fmt.Sprintln(p.pname(p.Name, 2), ":", red.bold(r.Name), red.regular(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}
|
||||
p.stamp("error", out, msg, r.Out)
|
||||
} else {
|
||||
|
|
|
@ -33,6 +33,7 @@ type (
|
|||
LogWriter struct{}
|
||||
)
|
||||
|
||||
// init check
|
||||
func init() {
|
||||
// custom log
|
||||
log.SetFlags(0)
|
||||
|
|
|
@ -5,10 +5,12 @@ import (
|
|||
"gopkg.in/urfave/cli.v2"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// Schema projects list
|
||||
type Schema struct {
|
||||
Projects []Project `yaml:"projects" json:"projects"`
|
||||
Projects []Project `yaml:"schema" json:"schema"`
|
||||
}
|
||||
|
||||
// Add a project if unique
|
||||
|
|
3
style.go
3
style.go
|
@ -13,12 +13,15 @@ var (
|
|||
magenta = colorBase(color.FgHiMagenta)
|
||||
)
|
||||
|
||||
// ColorBase type
|
||||
type colorBase color.Attribute
|
||||
|
||||
// Regular font with a color
|
||||
func (c colorBase) regular(a ...interface{}) string {
|
||||
return color.New(color.Attribute(c)).Sprint(a...)
|
||||
}
|
||||
|
||||
// Bold font with a color
|
||||
func (c colorBase) bold(a ...interface{}) string {
|
||||
return color.New(color.Attribute(c), color.Bold).Sprint(a...)
|
||||
}
|
||||
|
|
5
tools.go
5
tools.go
|
@ -8,6 +8,7 @@ import (
|
|||
"strings"
|
||||
)
|
||||
|
||||
// Tool info
|
||||
type Tool struct {
|
||||
Args []string `yaml:"args,omitempty" json:"args,omitempty"`
|
||||
Method string `yaml:"method,omitempty" json:"method,omitempty"`
|
||||
|
@ -19,6 +20,7 @@ type Tool struct {
|
|||
name string
|
||||
}
|
||||
|
||||
// Tools go
|
||||
type Tools struct {
|
||||
Fix Tool `yaml:"fix,omitempty" json:"fix,omitempty"`
|
||||
Clean Tool `yaml:"clean,omitempty" json:"clean,omitempty"`
|
||||
|
@ -31,6 +33,7 @@ type Tools struct {
|
|||
Run bool `yaml:"run,omitempty" json:"run,omitempty"`
|
||||
}
|
||||
|
||||
// Setup go tools
|
||||
func (t *Tools) Setup() {
|
||||
// go clean
|
||||
if t.Clean.Status {
|
||||
|
@ -92,6 +95,7 @@ func (t *Tools) Setup() {
|
|||
}
|
||||
}
|
||||
|
||||
// Exec a go tool
|
||||
func (t *Tool) Exec(path string, stop <-chan bool) (response Response) {
|
||||
if t.dir && filepath.Ext(path) != "" {
|
||||
path = filepath.Dir(path)
|
||||
|
@ -132,6 +136,7 @@ func (t *Tool) Exec(path string, stop <-chan bool) (response Response) {
|
|||
return
|
||||
}
|
||||
|
||||
// Compile is used for build and install
|
||||
func (t *Tool) Compile(path string, stop <-chan bool) (response Response) {
|
||||
var out bytes.Buffer
|
||||
var stderr bytes.Buffer
|
||||
|
|
Loading…
Reference in New Issue