mirror of
https://github.com/go-task/task.git
synced 2025-07-17 01:43:07 +02:00
@ -87,6 +87,11 @@ func main() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ctx := context.Background()
|
||||||
|
if !watch {
|
||||||
|
ctx = getSignalContext()
|
||||||
|
}
|
||||||
|
|
||||||
e := task.Executor{
|
e := task.Executor{
|
||||||
Force: force,
|
Force: force,
|
||||||
Watch: watch,
|
Watch: watch,
|
||||||
@ -95,7 +100,7 @@ func main() {
|
|||||||
Dir: dir,
|
Dir: dir,
|
||||||
Dry: dry,
|
Dry: dry,
|
||||||
|
|
||||||
Context: getSignalContext(),
|
Context: ctx,
|
||||||
|
|
||||||
Stdin: os.Stdin,
|
Stdin: os.Stdin,
|
||||||
Stdout: os.Stdout,
|
Stdout: os.Stdout,
|
||||||
|
28
watch.go
28
watch.go
@ -2,7 +2,10 @@ package task
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"os"
|
||||||
|
"os/signal"
|
||||||
"strings"
|
"strings"
|
||||||
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/go-task/task/internal/taskfile"
|
"github.com/go-task/task/internal/taskfile"
|
||||||
@ -40,6 +43,8 @@ func (e *Executor) watchTasks(calls ...taskfile.Call) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
closeOnInterrupt(w)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
@ -66,6 +71,7 @@ func (e *Executor) watchTasks(calls ...taskfile.Call) error {
|
|||||||
e.Logger.Errf("%v", err)
|
e.Logger.Errf("%v", err)
|
||||||
}
|
}
|
||||||
case <-w.Closed:
|
case <-w.Closed:
|
||||||
|
cancel()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -84,6 +90,19 @@ func (e *Executor) watchTasks(calls ...taskfile.Call) error {
|
|||||||
return w.Start(time.Second)
|
return w.Start(time.Second)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func isContextError(err error) bool {
|
||||||
|
return err == context.Canceled || err == context.DeadlineExceeded
|
||||||
|
}
|
||||||
|
|
||||||
|
func closeOnInterrupt(w *watcher.Watcher) {
|
||||||
|
ch := make(chan os.Signal, 1)
|
||||||
|
signal.Notify(ch, os.Interrupt, os.Kill, syscall.SIGTERM)
|
||||||
|
go func() {
|
||||||
|
<-ch
|
||||||
|
w.Close()
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
func (e *Executor) registerWatchedFiles(w *watcher.Watcher, calls ...taskfile.Call) error {
|
func (e *Executor) registerWatchedFiles(w *watcher.Watcher, calls ...taskfile.Call) error {
|
||||||
oldWatchedFiles := make(map[string]struct{})
|
oldWatchedFiles := make(map[string]struct{})
|
||||||
for f := range w.WatchedFiles() {
|
for f := range w.WatchedFiles() {
|
||||||
@ -140,12 +159,3 @@ func (e *Executor) registerWatchedFiles(w *watcher.Watcher, calls ...taskfile.Ca
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func isContextError(err error) bool {
|
|
||||||
switch err {
|
|
||||||
case context.Canceled, context.DeadlineExceeded:
|
|
||||||
return true
|
|
||||||
default:
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Reference in New Issue
Block a user