append "errorOutputPattern" property for projects
This commit is contained in:
parent
db7e339068
commit
455a243951
@ -8,6 +8,7 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
@ -20,6 +21,19 @@ func (p *Project) goRun(channel chan bool, runner chan bool, wr *sync.WaitGroup)
|
||||
var build *exec.Cmd
|
||||
var params []string
|
||||
var path = ""
|
||||
isErrorText := func(string) bool {
|
||||
return false
|
||||
}
|
||||
errRegexp, err := regexp.Compile(p.ErrorOutputPattern)
|
||||
if err != nil {
|
||||
msg := fmt.Sprintln(p.pname(p.Name, 3), ":", style.Blue.Regular(err.Error()))
|
||||
out := BufferOut{Time: time.Now(), Text: err.Error(), Type: "Go Run"}
|
||||
p.print("error", out, msg, "")
|
||||
} else {
|
||||
isErrorText = func(t string) bool {
|
||||
return errRegexp.MatchString(t)
|
||||
}
|
||||
}
|
||||
for _, param := range p.Params {
|
||||
arr := strings.Fields(param)
|
||||
params = append(params, arr...)
|
||||
@ -70,16 +84,14 @@ func (p *Project) goRun(channel chan bool, runner chan bool, wr *sync.WaitGroup)
|
||||
stopOutput, stopError := make(chan bool, 1), make(chan bool, 1)
|
||||
scanner := func(stop chan bool, output *bufio.Scanner, isError bool) {
|
||||
for output.Scan() {
|
||||
select {
|
||||
default:
|
||||
msg := fmt.Sprintln(p.pname(p.Name, 3), ":", style.Blue.Regular(output.Text()))
|
||||
if isError {
|
||||
out := BufferOut{Time: time.Now(), Text: output.Text(), Type: "Go Run"}
|
||||
p.print("error", out, msg, "")
|
||||
} else {
|
||||
out := BufferOut{Time: time.Now(), Text: output.Text()}
|
||||
p.print("out", out, msg, "")
|
||||
}
|
||||
text := output.Text()
|
||||
msg := fmt.Sprintln(p.pname(p.Name, 3), ":", style.Blue.Regular(text))
|
||||
if isError || isErrorText(text) {
|
||||
out := BufferOut{Time: time.Now(), Text: text, Type: "Go Run"}
|
||||
p.print("error", out, msg, "")
|
||||
} else {
|
||||
out := BufferOut{Time: time.Now(), Text: text}
|
||||
p.print("out", out, msg, "")
|
||||
}
|
||||
}
|
||||
close(stop)
|
||||
|
@ -33,23 +33,24 @@ type Blueprint struct {
|
||||
|
||||
// Project defines the informations of a single project
|
||||
type Project struct {
|
||||
settings.Settings `yaml:"-"`
|
||||
LastChangedOn time.Time `yaml:"-" json:"-"`
|
||||
base string
|
||||
Name string `yaml:"name" json:"name"`
|
||||
Path string `yaml:"path" json:"path"`
|
||||
Fmt bool `yaml:"fmt" json:"fmt"`
|
||||
Generate bool `yaml:"generate" json:"generate"`
|
||||
Test bool `yaml:"test" json:"test"`
|
||||
Bin bool `yaml:"bin" json:"bin"`
|
||||
Build bool `yaml:"build" json:"build"`
|
||||
Run bool `yaml:"run" json:"run"`
|
||||
Params []string `yaml:"params,omitempty" json:"params,omitempty"`
|
||||
Watcher Watcher `yaml:"watcher" json:"watcher"`
|
||||
Streams Streams `yaml:"streams" json:"streams"`
|
||||
Buffer Buffer `yaml:"-" json:"buffer"`
|
||||
parent *Blueprint
|
||||
path string
|
||||
settings.Settings `yaml:"-"`
|
||||
LastChangedOn time.Time `yaml:"-" json:"-"`
|
||||
base string
|
||||
Name string `yaml:"name" json:"name"`
|
||||
Path string `yaml:"path" json:"path"`
|
||||
Fmt bool `yaml:"fmt" json:"fmt"`
|
||||
Generate bool `yaml:"generate" json:"generate"`
|
||||
Test bool `yaml:"test" json:"test"`
|
||||
Bin bool `yaml:"bin" json:"bin"`
|
||||
Build bool `yaml:"build" json:"build"`
|
||||
Run bool `yaml:"run" json:"run"`
|
||||
Params []string `yaml:"params,omitempty" json:"params,omitempty"`
|
||||
Watcher Watcher `yaml:"watcher" json:"watcher"`
|
||||
Streams Streams `yaml:"streams" json:"streams"`
|
||||
ErrorOutputPattern string `yaml:"errorOutputPattern" json:"errorOutputPattern"`
|
||||
Buffer Buffer `yaml:"-" json:"buffer"`
|
||||
parent *Blueprint
|
||||
path string
|
||||
}
|
||||
|
||||
// Watcher struct defines the livereload's logic
|
||||
|
Loading…
Reference in New Issue
Block a user