watcher exit
This commit is contained in:
parent
01cb2287fb
commit
608a1a64d0
|
@ -44,8 +44,8 @@ func (p *Project) GoRun(channel chan bool, runner chan bool, wr *sync.WaitGroup)
|
||||||
}
|
}
|
||||||
close(runner)
|
close(runner)
|
||||||
|
|
||||||
execOutput := bufio.NewScanner(stdout)
|
execOutput, execError := bufio.NewScanner(stdout), bufio.NewScanner(stderr)
|
||||||
execError := bufio.NewScanner(stderr)
|
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() {
|
||||||
|
@ -60,7 +60,7 @@ func (p *Project) GoRun(channel chan bool, runner chan bool, wr *sync.WaitGroup)
|
||||||
log.Println(pname(p.Name, 3), ":", BlueS(output.Text()))
|
log.Println(pname(p.Name, 3), ":", BlueS(output.Text()))
|
||||||
}
|
}
|
||||||
if p.Watcher.Output["file"] {
|
if p.Watcher.Output["file"] {
|
||||||
path := filepath.Join(p.base, Bp.Files["output"])
|
path := filepath.Join(p.base, B.Files["output"])
|
||||||
f := create(path)
|
f := create(path)
|
||||||
t := time.Now()
|
t := time.Now()
|
||||||
if _, err := f.WriteString(t.Format("2006-01-02 15:04:05") + " : " + output.Text() + "\r\n"); err != nil {
|
if _, err := f.WriteString(t.Format("2006-01-02 15:04:05") + " : " + output.Text() + "\r\n"); err != nil {
|
||||||
|
@ -71,8 +71,6 @@ func (p *Project) GoRun(channel chan bool, runner chan bool, wr *sync.WaitGroup)
|
||||||
}
|
}
|
||||||
close(stop)
|
close(stop)
|
||||||
}
|
}
|
||||||
stopOutput := make(chan bool, 1)
|
|
||||||
stopError := make(chan bool, 1)
|
|
||||||
go scanner(stopOutput, execOutput, false)
|
go scanner(stopOutput, execOutput, false)
|
||||||
go scanner(stopError, execError, true)
|
go scanner(stopError, execError, true)
|
||||||
|
|
||||||
|
@ -86,7 +84,6 @@ func (p *Project) GoRun(channel chan bool, runner chan bool, wr *sync.WaitGroup)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GoBuild is an implementation of the "go build"
|
// GoBuild is an implementation of the "go build"
|
||||||
|
|
|
@ -25,7 +25,7 @@ func (p *Project) watching() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(strings.ToUpper(pname(p.Name, 1)), ":", Red(err.Error()))
|
log.Println(strings.ToUpper(pname(p.Name, 1)), ":", Red(err.Error()))
|
||||||
}
|
}
|
||||||
channel := make(chan bool, 1)
|
channel, exit := make(chan bool, 1), make(chan bool, 1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(pname(p.Name, 1), ":", Red(err.Error()))
|
log.Println(pname(p.Name, 1), ":", Red(err.Error()))
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ func (p *Project) watching() {
|
||||||
}
|
}
|
||||||
defer end()
|
defer end()
|
||||||
|
|
||||||
p.cmd()
|
p.cmd(exit)
|
||||||
err = p.walks(watcher)
|
err = p.walks(watcher)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(pname(p.Name, 1), ":", Red(err.Error()))
|
fmt.Println(pname(p.Name, 1), ":", Red(err.Error()))
|
||||||
|
@ -83,6 +83,8 @@ func (p *Project) watching() {
|
||||||
}
|
}
|
||||||
case err := <-watcher.Errors:
|
case err := <-watcher.Errors:
|
||||||
log.Println(Red(err.Error()))
|
log.Println(Red(err.Error()))
|
||||||
|
case <-exit:
|
||||||
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -141,7 +143,7 @@ func (p *Project) fmt(path string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cmd calls an wrapper for execute the commands after/before
|
// Cmd calls an wrapper for execute the commands after/before
|
||||||
func (p *Project) cmd() {
|
func (p *Project) cmd(exit chan bool) {
|
||||||
c := make(chan os.Signal, 2)
|
c := make(chan os.Signal, 2)
|
||||||
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
|
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
|
||||||
cast := func(commands []string) {
|
cast := func(commands []string) {
|
||||||
|
@ -163,7 +165,7 @@ func (p *Project) cmd() {
|
||||||
if len(p.Watcher.After) > 0 {
|
if len(p.Watcher.After) > 0 {
|
||||||
cast(p.Watcher.After)
|
cast(p.Watcher.After)
|
||||||
}
|
}
|
||||||
os.Exit(1)
|
close(exit)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
Loading…
Reference in New Issue