removed io writer
This commit is contained in:
parent
03323b90a4
commit
c86bb98927
|
@ -3,8 +3,6 @@ package cli
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
@ -134,55 +132,42 @@ func (p *Project) goInstall() (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// GoFmt is an implementation of the gofmt
|
// GoFmt is an implementation of the gofmt
|
||||||
func (p *Project) goFmt(path string) (io.Writer, error) {
|
func (p *Project) goFmt(path string) (string, error) {
|
||||||
defer func() {
|
var out, stderr bytes.Buffer
|
||||||
p.sync()
|
|
||||||
}()
|
|
||||||
var out bytes.Buffer
|
|
||||||
build := exec.Command("gofmt", "-s", "-w", "-e", path)
|
build := exec.Command("gofmt", "-s", "-w", "-e", path)
|
||||||
build.Dir = p.base
|
build.Dir = p.base
|
||||||
build.Stdout = &out
|
build.Stdout = &out
|
||||||
build.Stderr = &out
|
build.Stderr = &stderr
|
||||||
if err := build.Run(); err != nil {
|
if err := build.Run(); err != nil {
|
||||||
fmt.Print("append")
|
return stderr.String(), err
|
||||||
p.Buffer.StdErr = append(p.Buffer.StdErr, BufferOut{Time: time.Now(), Text: err.Error()})
|
|
||||||
return build.Stderr, err
|
|
||||||
}
|
}
|
||||||
return nil, nil
|
return "", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GoTest is an implementation of the go test
|
// GoTest is an implementation of the go test
|
||||||
func (p *Project) goTest(path string) (io.Writer, error) {
|
func (p *Project) goTest(path string) (string, error) {
|
||||||
defer func() {
|
var out, stderr bytes.Buffer
|
||||||
p.sync()
|
|
||||||
}()
|
|
||||||
var out bytes.Buffer
|
|
||||||
build := exec.Command("go", "test")
|
build := exec.Command("go", "test")
|
||||||
build.Dir = path
|
build.Dir = path
|
||||||
build.Stdout = &out
|
build.Stdout = &out
|
||||||
build.Stderr = &out
|
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 build.Stdout, err
|
|
||||||
}
|
}
|
||||||
return nil, nil
|
return "", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GoGenerate is an implementation of the go test
|
// GoGenerate is an implementation of the go test
|
||||||
func (p *Project) goGenerate(path string) (io.Writer, error) {
|
func (p *Project) goGenerate(path string) (string, error) {
|
||||||
defer func() {
|
var out, stderr bytes.Buffer
|
||||||
p.sync()
|
|
||||||
}()
|
|
||||||
var out bytes.Buffer
|
|
||||||
build := exec.Command("go", "generate")
|
build := exec.Command("go", "generate")
|
||||||
build.Dir = path
|
build.Dir = path
|
||||||
build.Stdout = &out
|
build.Stdout = &out
|
||||||
build.Stderr = &out
|
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 build.Stdout, err
|
|
||||||
}
|
}
|
||||||
return nil, nil
|
return "", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cmds exec a list of defined commands
|
// Cmds exec a list of defined commands
|
||||||
|
@ -193,7 +178,6 @@ func (p *Project) cmds(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)
|
||||||
return errors
|
return errors
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,11 +86,16 @@ func (p *Project) watching() {
|
||||||
|
|
||||||
// Install calls an implementation of the "go install"
|
// Install calls an implementation of the "go install"
|
||||||
func (p *Project) install(channel chan bool, wr *sync.WaitGroup) {
|
func (p *Project) install(channel chan bool, wr *sync.WaitGroup) {
|
||||||
|
defer func() {
|
||||||
|
p.sync()
|
||||||
|
}()
|
||||||
if p.Bin {
|
if p.Bin {
|
||||||
log.Println(p.pname(p.Name, 1), ":", "Installing..")
|
log.Println(p.pname(p.Name, 1), ":", "Installing..")
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
if std, err := p.goInstall(); err != nil {
|
if stream, err := p.goInstall(); err != nil {
|
||||||
log.Println(p.pname(p.Name, 1), ":", fmt.Sprint(p.Red.Bold(err)), std)
|
p.Buffer.StdErr = append(p.Buffer.StdErr, BufferOut{Time: time.Now(), Text: err.Error(), Type: "Go Install", Stream: stream})
|
||||||
|
log.Println(p.pname(p.Name, 1), p.Red.Bold("Go Install"), p.Red.Regular(err.Error()))
|
||||||
|
fmt.Println(stream)
|
||||||
wr.Done()
|
wr.Done()
|
||||||
} else {
|
} else {
|
||||||
log.Println(p.pname(p.Name, 5), ":", p.Green.Regular("Installed")+" after", p.Magenta.Regular(big.NewFloat(float64(time.Since(start).Seconds())).Text('f', 3), " s"))
|
log.Println(p.pname(p.Name, 5), ":", p.Green.Regular("Installed")+" after", p.Magenta.Regular(big.NewFloat(float64(time.Since(start).Seconds())).Text('f', 3), " s"))
|
||||||
|
@ -114,11 +119,16 @@ func (p *Project) install(channel chan bool, wr *sync.WaitGroup) {
|
||||||
|
|
||||||
// Build calls an implementation of the "go build"
|
// Build calls an implementation of the "go build"
|
||||||
func (p *Project) build() {
|
func (p *Project) build() {
|
||||||
|
defer func() {
|
||||||
|
p.sync()
|
||||||
|
}()
|
||||||
if p.Build {
|
if p.Build {
|
||||||
log.Println(p.pname(p.Name, 1), ":", "Building..")
|
log.Println(p.pname(p.Name, 1), ":", "Building..")
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
if std, err := p.goBuild(); err != nil {
|
if stream, err := p.goBuild(); err != nil {
|
||||||
log.Println(p.pname(p.Name, 1), ":", fmt.Sprint(p.Red.Bold(err)), std)
|
p.Buffer.StdErr = append(p.Buffer.StdErr, BufferOut{Time: time.Now(), Text: err.Error(), Type: "Go Build", Stream: stream})
|
||||||
|
log.Println(p.pname(p.Name, 1), p.Red.Bold("Go Build"), p.Red.Regular(err.Error()))
|
||||||
|
fmt.Println(stream)
|
||||||
} else {
|
} else {
|
||||||
log.Println(p.pname(p.Name, 5), ":", p.Green.Regular("Builded")+" after", p.Magenta.Regular(big.NewFloat(float64(time.Since(start).Seconds())).Text('f', 3), " s"))
|
log.Println(p.pname(p.Name, 5), ":", p.Green.Regular("Builded")+" after", p.Magenta.Regular(big.NewFloat(float64(time.Since(start).Seconds())).Text('f', 3), " s"))
|
||||||
}
|
}
|
||||||
|
@ -128,9 +138,13 @@ func (p *Project) build() {
|
||||||
|
|
||||||
// Fmt calls an implementation of the "go fmt"
|
// Fmt calls an implementation of the "go fmt"
|
||||||
func (p *Project) fmt(path string) error {
|
func (p *Project) fmt(path string) error {
|
||||||
|
defer func() {
|
||||||
|
p.sync()
|
||||||
|
}()
|
||||||
if p.Fmt {
|
if p.Fmt {
|
||||||
if stream, err := p.goFmt(path); err != nil {
|
if stream, err := p.goFmt(path); err != nil {
|
||||||
log.Println(p.pname(p.Name, 1), p.Red.Bold("go Fmt"), p.Red.Bold("there are some errors in"), ":", p.Magenta.Bold(path))
|
p.Buffer.StdErr = append(p.Buffer.StdErr, BufferOut{Time: time.Now(), Text: "there are some errors in", Path: path, Type: "Go Fmt", Stream: stream})
|
||||||
|
log.Println(p.pname(p.Name, 1), p.Red.Bold("Go Fmt"), p.Red.Regular("there are some errors in"), ":", p.Magenta.Bold(path))
|
||||||
fmt.Println(stream)
|
fmt.Println(stream)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -140,9 +154,13 @@ func (p *Project) fmt(path string) error {
|
||||||
|
|
||||||
// Generate calls an implementation of the "go generate"
|
// Generate calls an implementation of the "go generate"
|
||||||
func (p *Project) generate(path string) error {
|
func (p *Project) generate(path string) error {
|
||||||
|
defer func() {
|
||||||
|
p.sync()
|
||||||
|
}()
|
||||||
if p.Generate {
|
if p.Generate {
|
||||||
if stream, err := p.goGenerate(path); err != nil {
|
if stream, err := p.goGenerate(path); err != nil {
|
||||||
log.Println(p.pname(p.Name, 1), p.Red.Bold("go Generate"), p.Red.Bold("there are some errors in"), ":", p.Magenta.Bold(path))
|
p.Buffer.StdErr = append(p.Buffer.StdErr, BufferOut{Time: time.Now(), Text: "there are some errors in", Path: path, Type: "Go Generate", Stream: stream})
|
||||||
|
log.Println(p.pname(p.Name, 1), p.Red.Bold("Go Generate"), p.Red.Regular("there are some errors in"), ":", p.Magenta.Bold(path))
|
||||||
fmt.Println(stream)
|
fmt.Println(stream)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -157,6 +175,7 @@ func (p *Project) cmd(exit chan bool) {
|
||||||
cast := func(commands []string) {
|
cast := func(commands []string) {
|
||||||
if errs := p.cmds(commands); errs != nil {
|
if errs := p.cmds(commands); errs != nil {
|
||||||
for _, err := range errs {
|
for _, err := range errs {
|
||||||
|
|
||||||
log.Println(p.pname(p.Name, 2), p.Red.Bold(err))
|
log.Println(p.pname(p.Name, 2), p.Red.Bold(err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -181,9 +200,13 @@ func (p *Project) cmd(exit chan bool) {
|
||||||
|
|
||||||
// Test calls an implementation of the "go test"
|
// Test calls an implementation of the "go test"
|
||||||
func (p *Project) test(path string) error {
|
func (p *Project) test(path string) error {
|
||||||
|
defer func() {
|
||||||
|
p.sync()
|
||||||
|
}()
|
||||||
if p.Test {
|
if p.Test {
|
||||||
if stream, err := p.goTest(path); err != nil {
|
if stream, err := p.goTest(path); err != nil {
|
||||||
log.Println(p.pname(p.Name, 1), p.Red.Bold("go Test fails in "), ":", p.Magenta.Bold(path))
|
p.Buffer.StdErr = append(p.Buffer.StdErr, BufferOut{Time: time.Now(), Text: "there are some errors in", Path: path, Type: "Go Test", Stream: stream})
|
||||||
|
log.Println(p.pname(p.Name, 1), p.Red.Bold("Go Test"), p.Red.Regular("there are some errors in "), ":", p.Magenta.Bold(path))
|
||||||
fmt.Println(stream)
|
fmt.Println(stream)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue