diff --git a/cmd/root.go b/cmd/root.go index dde733c..23f4280 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -1,9 +1,7 @@ package cmd import ( - "fmt" - "os" - + "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) @@ -21,8 +19,8 @@ var rootCmd = &cobra.Command{ func Execute() { err := rootCmd.Execute() if err != nil { - fmt.Fprintln(os.Stderr, err) - os.Exit(1) + logrus.Error(err) + return } } diff --git a/src/haunt/projects.go b/src/haunt/projects.go index 63a0845..24de696 100644 --- a/src/haunt/projects.go +++ b/src/haunt/projects.go @@ -258,6 +258,14 @@ func (p *Project) Reload(path string, stop <-chan bool) { p.stamp("error", out, msg, "") } }() + } else { + if install.Err != nil { + log.Println(p.parent.Prefix("Install failed for: " + p.Name + " exiting")) + } + if build.Err != nil { + log.Println(p.parent.Prefix("Build failed for: " + p.Name + " exiting")) + } + os.Exit(0) } if done { return @@ -667,7 +675,7 @@ func (r *Response) print(start time.Time, p *Project) { if r.Err != nil { msg = fmt.Sprintln(p.pname(p.Name, 2), ":", Red.Bold(r.Name), "\n", r.Err.Error()) out = BufferOut{Time: time.Now(), Text: r.Err.Error(), Type: r.Name, Stream: r.Out} - p.stamp("error", out, msg, r.Out) + p.stamp("errororororororororor", out, msg, r.Out) } else { msg = fmt.Sprintln(p.pname(p.Name, 5), ":", Green.Bold(r.Name), "completed in", Magenta.Regular(big.NewFloat(float64(time.Since(start).Seconds())).Text('f', 3), " s")) out = BufferOut{Time: time.Now(), Text: r.Name + " in " + big.NewFloat(float64(time.Since(start).Seconds())).Text('f', 3) + " s"} diff --git a/src/haunt/tools.go b/src/haunt/tools.go index 3843f91..3c8661a 100644 --- a/src/haunt/tools.go +++ b/src/haunt/tools.go @@ -4,8 +4,8 @@ import ( "bytes" "errors" "fmt" - "io/ioutil" "log" + "os" "os/exec" "path/filepath" "strings" @@ -86,7 +86,6 @@ func (t *Tools) Setup() { // go install t.Install.name = "Install" t.Install.cmd = replace([]string{gocmd, "install"}, t.Install.Method) - fmt.Println(t.Install.cmd) t.Install.Args = split([]string{}, t.Install.Args) // go build if t.Build.Status { @@ -104,7 +103,7 @@ func (t *Tool) Exec(path string, stop <-chan bool) (response Response) { } // check if there is at least one go file matched := false - files, _ := ioutil.ReadDir(path) + files, _ := os.ReadDir(path) for _, f := range files { matched, _ = filepath.Match("*.go", f.Name()) if matched { @@ -180,14 +179,27 @@ func (t *Tool) Compile(path string, stop <-chan bool) (response Response) { cmd.Stdout = &out cmd.Stderr = &stderr // Start command - cmd.Start() - go func() { done <- cmd.Wait() }() + err := cmd.Start() + if err != nil { + err := cmd.Process.Kill() + if err != nil { + fmt.Println(err.Error()) + return + } + } + go func() { + done <- cmd.Wait() + }() // Wait a result response.Name = t.name select { case <-stop: // Stop running command - cmd.Process.Kill() + err := cmd.Process.Kill() + if err != nil { + fmt.Println(err.Error()) + return + } case err := <-done: // Command completed if err != nil {