buffer errors

This commit is contained in:
alessio 2016-11-11 17:22:25 +01:00
parent b5236cb608
commit 8f48b29950
1 changed files with 25 additions and 4 deletions

View File

@ -3,6 +3,7 @@ package cli
import ( import (
"bufio" "bufio"
"bytes" "bytes"
"fmt"
"io" "io"
"log" "log"
"os" "os"
@ -63,11 +64,10 @@ func (p *Project) GoRun(channel chan bool, runner chan bool, wr *sync.WaitGroup)
p.Buffer.StdOut = append(p.Buffer.StdOut, BufferOut{Time: time.Now(), Text: output.Text()}) p.Buffer.StdOut = append(p.Buffer.StdOut, BufferOut{Time: time.Now(), Text: output.Text()})
} }
go sync() go sync()
if p.Cli.Streams {
if p.Watcher.Output["cli"] {
log.Println(p.pname(p.Name, 3), ":", p.Blue.Regular(output.Text())) log.Println(p.pname(p.Name, 3), ":", p.Blue.Regular(output.Text()))
} }
if p.Watcher.Output["file"] { if p.File.Streams {
path := filepath.Join(p.base, p.parent.Resources.Output) path := filepath.Join(p.base, p.parent.Resources.Output)
f := p.Create(path) f := p.Create(path)
t := time.Now() t := time.Now()
@ -104,6 +104,7 @@ func (p *Project) GoBuild() (string, error) {
build.Stdout = &out build.Stdout = &out
build.Stderr = &stderr build.Stderr = &stderr
if err := build.Run(); err != nil { if err := build.Run(); err != nil {
p.Buffer.StdErr = append(p.Buffer.StdErr, BufferOut{Time: time.Now(), Text: err.Error()})
return stderr.String(), err return stderr.String(), err
} }
return "", nil return "", nil
@ -115,13 +116,15 @@ func (p *Project) GoInstall() (string, error) {
var stderr bytes.Buffer var stderr bytes.Buffer
err := os.Setenv("GOBIN", filepath.Join(os.Getenv("GOPATH"), "bin")) err := os.Setenv("GOBIN", filepath.Join(os.Getenv("GOPATH"), "bin"))
if err != nil { if err != nil {
return "", nil p.Buffer.StdErr = append(p.Buffer.StdErr, BufferOut{Time: time.Now(), Text: err.Error()})
return "", err
} }
build := exec.Command("go", "install") build := exec.Command("go", "install")
build.Dir = p.base build.Dir = p.base
build.Stdout = &out build.Stdout = &out
build.Stderr = &stderr build.Stderr = &stderr
if err := build.Run(); err != nil { if err := build.Run(); err != nil {
p.Buffer.StdErr = append(p.Buffer.StdErr, BufferOut{Time: time.Now(), Text: err.Error()})
return stderr.String(), err return stderr.String(), err
} }
return "", nil return "", nil
@ -135,6 +138,8 @@ func (p *Project) GoFmt(path string) (io.Writer, error) {
build.Stdout = &out build.Stdout = &out
build.Stderr = &out build.Stderr = &out
if err := build.Run(); err != nil { if err := build.Run(); err != nil {
fmt.Print("append")
p.Buffer.StdErr = append(p.Buffer.StdErr, BufferOut{Time: time.Now(), Text: err.Error()})
return build.Stderr, err return build.Stderr, err
} }
return nil, nil return nil, nil
@ -148,6 +153,21 @@ func (p *Project) GoTest(path string) (io.Writer, error) {
build.Stdout = &out build.Stdout = &out
build.Stderr = &out build.Stderr = &out
if err := build.Run(); err != nil { if err := build.Run(); err != nil {
p.Buffer.StdErr = append(p.Buffer.StdErr, BufferOut{Time: time.Now(), Text: err.Error()})
return build.Stdout, err
}
return nil, nil
}
// GoGenerate is an implementation of the go test
func (p *Project) GoGenerate(path string) (io.Writer, error) {
var out bytes.Buffer
build := exec.Command("go", "generate")
build.Dir = path
build.Stdout = &out
build.Stderr = &out
if err := build.Run(); err != nil {
p.Buffer.StdErr = append(p.Buffer.StdErr, BufferOut{Time: time.Now(), Text: err.Error()})
return build.Stdout, err return build.Stdout, err
} }
return nil, nil return nil, nil
@ -161,6 +181,7 @@ func (p *Project) Cmd(cmds []string) (errors []error) {
build := exec.Command(c[0], c[1:]...) build := exec.Command(c[0], c[1:]...)
build.Dir = p.base build.Dir = p.base
if err := build.Run(); err != nil { if err := build.Run(); err != nil {
p.Buffer.StdErr = append(p.Buffer.StdErr, BufferOut{Time: time.Now(), Text: err.Error()})
errors = append(errors, err) errors = append(errors, err)
} }
} }