append "errorOutputPattern" property for projects

This commit is contained in:
Kyoichiro Yamada 2017-04-20 17:22:09 +09:00
parent db7e339068
commit 455a243951
2 changed files with 40 additions and 27 deletions

View File

@ -8,6 +8,7 @@ import (
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"regexp"
"strings" "strings"
"sync" "sync"
"time" "time"
@ -20,6 +21,19 @@ func (p *Project) goRun(channel chan bool, runner chan bool, wr *sync.WaitGroup)
var build *exec.Cmd var build *exec.Cmd
var params []string var params []string
var path = "" 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 { for _, param := range p.Params {
arr := strings.Fields(param) arr := strings.Fields(param)
params = append(params, arr...) 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) stopOutput, stopError := make(chan bool, 1), make(chan bool, 1)
scanner := func(stop chan bool, output *bufio.Scanner, isError bool) { scanner := func(stop chan bool, output *bufio.Scanner, isError bool) {
for output.Scan() { for output.Scan() {
select { text := output.Text()
default: msg := fmt.Sprintln(p.pname(p.Name, 3), ":", style.Blue.Regular(text))
msg := fmt.Sprintln(p.pname(p.Name, 3), ":", style.Blue.Regular(output.Text())) if isError || isErrorText(text) {
if isError { out := BufferOut{Time: time.Now(), Text: text, Type: "Go Run"}
out := BufferOut{Time: time.Now(), Text: output.Text(), Type: "Go Run"} p.print("error", out, msg, "")
p.print("error", out, msg, "") } else {
} else { out := BufferOut{Time: time.Now(), Text: text}
out := BufferOut{Time: time.Now(), Text: output.Text()} p.print("out", out, msg, "")
p.print("out", out, msg, "")
}
} }
} }
close(stop) close(stop)

View File

@ -33,23 +33,24 @@ type Blueprint struct {
// Project defines the informations of a single project // Project defines the informations of a single project
type Project struct { type Project struct {
settings.Settings `yaml:"-"` settings.Settings `yaml:"-"`
LastChangedOn time.Time `yaml:"-" json:"-"` LastChangedOn time.Time `yaml:"-" json:"-"`
base string base string
Name string `yaml:"name" json:"name"` Name string `yaml:"name" json:"name"`
Path string `yaml:"path" json:"path"` Path string `yaml:"path" json:"path"`
Fmt bool `yaml:"fmt" json:"fmt"` Fmt bool `yaml:"fmt" json:"fmt"`
Generate bool `yaml:"generate" json:"generate"` Generate bool `yaml:"generate" json:"generate"`
Test bool `yaml:"test" json:"test"` Test bool `yaml:"test" json:"test"`
Bin bool `yaml:"bin" json:"bin"` Bin bool `yaml:"bin" json:"bin"`
Build bool `yaml:"build" json:"build"` Build bool `yaml:"build" json:"build"`
Run bool `yaml:"run" json:"run"` Run bool `yaml:"run" json:"run"`
Params []string `yaml:"params,omitempty" json:"params,omitempty"` Params []string `yaml:"params,omitempty" json:"params,omitempty"`
Watcher Watcher `yaml:"watcher" json:"watcher"` Watcher Watcher `yaml:"watcher" json:"watcher"`
Streams Streams `yaml:"streams" json:"streams"` Streams Streams `yaml:"streams" json:"streams"`
Buffer Buffer `yaml:"-" json:"buffer"` ErrorOutputPattern string `yaml:"errorOutputPattern" json:"errorOutputPattern"`
parent *Blueprint Buffer Buffer `yaml:"-" json:"buffer"`
path string parent *Blueprint
path string
} }
// Watcher struct defines the livereload's logic // Watcher struct defines the livereload's logic