Fix bee generate output in watch.go

This removes the output of bee generate in watch.go as it shows
the entire logger output (including the banner). Added also the ability
to catch the exec.Command error instead of returning the exit status.
This commit is contained in:
Faissal Elamraoui 2016-12-11 23:39:59 +01:00
parent 9786cb47ea
commit a0020d65af
1 changed files with 19 additions and 16 deletions

View File

@ -120,8 +120,6 @@ func AutoBuild(files []string, isgenerate bool) {
state.Lock() state.Lock()
defer state.Unlock() defer state.Unlock()
logger.Info("Start building...")
os.Chdir(currpath) os.Chdir(currpath)
cmdName := "go" cmdName := "go"
@ -129,17 +127,20 @@ func AutoBuild(files []string, isgenerate bool) {
cmdName = "gopm" cmdName = "gopm"
} }
var err error var (
err error
stderr bytes.Buffer
stdout bytes.Buffer
)
// For applications use full import path like "github.com/.../.." // For applications use full import path like "github.com/.../.."
// are able to use "go install" to reduce build time. // are able to use "go install" to reduce build time.
if conf.GoInstall || conf.Gopm.Install { if conf.GoInstall || conf.Gopm.Install {
icmd := exec.Command("go", "list", "./...") icmd := exec.Command("go", "list", "./...")
buf := bytes.NewBuffer([]byte("")) icmd.Stdout = &stdout
icmd.Stdout = buf
icmd.Env = append(os.Environ(), "GOGC=off") icmd.Env = append(os.Environ(), "GOGC=off")
err = icmd.Run() err = icmd.Run()
if err == nil { if err == nil {
list := strings.Split(buf.String(), "\n")[1:] list := strings.Split(stdout.String(), "\n")[1:]
for _, pkg := range list { for _, pkg := range list {
if len(pkg) == 0 { if len(pkg) == 0 {
continue continue
@ -157,12 +158,15 @@ func AutoBuild(files []string, isgenerate bool) {
} }
if isgenerate { if isgenerate {
logger.Info("Generating the docs...")
icmd := exec.Command("bee", "generate", "docs") icmd := exec.Command("bee", "generate", "docs")
icmd.Env = append(os.Environ(), "GOGC=off") icmd.Env = append(os.Environ(), "GOGC=off")
icmd.Stdout = os.Stdout err = icmd.Run()
icmd.Stderr = os.Stderr if err != nil {
icmd.Run() logger.Errorf("Failed to generate the docs.")
logger.Info("============== Generate Docs ===================") return
}
logger.Success("Docs generated!")
} }
if err == nil { if err == nil {
@ -180,15 +184,14 @@ func AutoBuild(files []string, isgenerate bool) {
bcmd := exec.Command(cmdName, args...) bcmd := exec.Command(cmdName, args...)
bcmd.Env = append(os.Environ(), "GOGC=off") bcmd.Env = append(os.Environ(), "GOGC=off")
bcmd.Stdout = os.Stdout bcmd.Stderr = &stderr
bcmd.Stderr = os.Stderr
err = bcmd.Run() err = bcmd.Run()
if err != nil {
logger.Errorf("Failed to build the application: %s", stderr.String())
return
}
} }
if err != nil {
logger.Error("============== Build Failed ===================")
return
}
logger.Success("Built Successfully!") logger.Success("Built Successfully!")
Restart(appname) Restart(appname)
} }