mirror of
https://github.com/go-task/task.git
synced 2025-08-10 22:42:19 +02:00
fix: watch interval (#970)
This commit is contained in:
@@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
- Small bug fix: closing "Taskfile.yml" once we're done reading it
|
- Small bug fix: closing "Taskfile.yml" once we're done reading it
|
||||||
([#963](https://github.com/go-task/task/issues/963), [#964](https://github.com/go-task/task/pull/964) by @HeCorr).
|
([#963](https://github.com/go-task/task/issues/963), [#964](https://github.com/go-task/task/pull/964) by @HeCorr).
|
||||||
|
- Fixed a bug where watch intervals set in the Taskfile were not being respected ([#969](https://github.com/go-task/task/pull/969), [#970](https://github.com/go-task/task/pull/970) by @pd93)
|
||||||
- Add `--json` flag (alias `-j`) with the intent to improve support for code
|
- Add `--json` flag (alias `-j`) with the intent to improve support for code
|
||||||
editors and add room to other possible integrations. This is basic for now,
|
editors and add room to other possible integrations. This is basic for now,
|
||||||
but we plan to add more info in the near future
|
but we plan to add more info in the near future
|
||||||
|
@@ -8,6 +8,7 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/spf13/pflag"
|
"github.com/spf13/pflag"
|
||||||
"mvdan.cc/sh/v3/syntax"
|
"mvdan.cc/sh/v3/syntax"
|
||||||
@@ -74,7 +75,7 @@ func main() {
|
|||||||
entrypoint string
|
entrypoint string
|
||||||
output taskfile.Output
|
output taskfile.Output
|
||||||
color bool
|
color bool
|
||||||
interval string
|
interval time.Duration
|
||||||
)
|
)
|
||||||
|
|
||||||
pflag.BoolVar(&versionFlag, "version", false, "show Task version")
|
pflag.BoolVar(&versionFlag, "version", false, "show Task version")
|
||||||
@@ -99,7 +100,7 @@ func main() {
|
|||||||
pflag.StringVar(&output.Group.End, "output-group-end", "", "message template to print after a task's grouped output")
|
pflag.StringVar(&output.Group.End, "output-group-end", "", "message template to print after a task's grouped output")
|
||||||
pflag.BoolVarP(&color, "color", "c", true, "colored output. Enabled by default. Set flag to false or use NO_COLOR=1 to disable")
|
pflag.BoolVarP(&color, "color", "c", true, "colored output. Enabled by default. Set flag to false or use NO_COLOR=1 to disable")
|
||||||
pflag.IntVarP(&concurrency, "concurrency", "C", 0, "limit number tasks to run concurrently")
|
pflag.IntVarP(&concurrency, "concurrency", "C", 0, "limit number tasks to run concurrently")
|
||||||
pflag.StringVarP(&interval, "interval", "I", "5s", "interval to watch for changes")
|
pflag.DurationVarP(&interval, "interval", "I", 0, "interval to watch for changes")
|
||||||
pflag.Parse()
|
pflag.Parse()
|
||||||
|
|
||||||
if versionFlag {
|
if versionFlag {
|
||||||
|
3
task.go
3
task.go
@@ -9,6 +9,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/go-task/task/v3/internal/compiler"
|
"github.com/go-task/task/v3/internal/compiler"
|
||||||
"github.com/go-task/task/v3/internal/execext"
|
"github.com/go-task/task/v3/internal/execext"
|
||||||
@@ -45,7 +46,7 @@ type Executor struct {
|
|||||||
Parallel bool
|
Parallel bool
|
||||||
Color bool
|
Color bool
|
||||||
Concurrency int
|
Concurrency int
|
||||||
Interval string
|
Interval time.Duration
|
||||||
|
|
||||||
Stdin io.Reader
|
Stdin io.Reader
|
||||||
Stdout io.Writer
|
Stdout io.Writer
|
||||||
|
@@ -3,6 +3,7 @@ package taskfile
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"time"
|
||||||
|
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
)
|
)
|
||||||
@@ -20,7 +21,7 @@ type Taskfile struct {
|
|||||||
Silent bool
|
Silent bool
|
||||||
Dotenv []string
|
Dotenv []string
|
||||||
Run string
|
Run string
|
||||||
Interval string
|
Interval time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tf *Taskfile) UnmarshalYAML(node *yaml.Node) error {
|
func (tf *Taskfile) UnmarshalYAML(node *yaml.Node) error {
|
||||||
@@ -39,7 +40,7 @@ func (tf *Taskfile) UnmarshalYAML(node *yaml.Node) error {
|
|||||||
Silent bool
|
Silent bool
|
||||||
Dotenv []string
|
Dotenv []string
|
||||||
Run string
|
Run string
|
||||||
Interval string
|
Interval time.Duration
|
||||||
}
|
}
|
||||||
if err := node.Decode(&taskfile); err != nil {
|
if err := node.Decode(&taskfile); err != nil {
|
||||||
return err
|
return err
|
||||||
|
33
watch.go
33
watch.go
@@ -38,23 +38,14 @@ func (e *Executor) watchTasks(calls ...taskfile.Call) error {
|
|||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
var watchIntervalString string
|
var watchInterval time.Duration
|
||||||
|
switch {
|
||||||
if e.Interval != "" {
|
case e.Interval != 0:
|
||||||
watchIntervalString = e.Interval
|
watchInterval = e.Interval
|
||||||
} else if e.Taskfile.Interval != "" {
|
case e.Taskfile.Interval != 0:
|
||||||
watchIntervalString = e.Taskfile.Interval
|
watchInterval = e.Taskfile.Interval
|
||||||
}
|
default:
|
||||||
|
watchInterval = defaultWatchInterval
|
||||||
watchInterval := defaultWatchInterval
|
|
||||||
|
|
||||||
if watchIntervalString != "" {
|
|
||||||
var err error
|
|
||||||
watchInterval, err = parseWatchInterval(watchIntervalString)
|
|
||||||
if err != nil {
|
|
||||||
cancel()
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
e.Logger.VerboseOutf(logger.Green, "task: Watching for changes every %v", watchInterval)
|
e.Logger.VerboseOutf(logger.Green, "task: Watching for changes every %v", watchInterval)
|
||||||
@@ -186,11 +177,3 @@ func (e *Executor) registerWatchedFiles(w *watcher.Watcher, calls ...taskfile.Ca
|
|||||||
func shouldIgnoreFile(path string) bool {
|
func shouldIgnoreFile(path string) bool {
|
||||||
return strings.Contains(path, "/.git") || strings.Contains(path, "/.task") || strings.Contains(path, "/node_modules")
|
return strings.Contains(path, "/.git") || strings.Contains(path, "/.task") || strings.Contains(path, "/node_modules")
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseWatchInterval(watchInterval string) (time.Duration, error) {
|
|
||||||
v, err := time.ParseDuration(watchInterval)
|
|
||||||
if err != nil {
|
|
||||||
return 0, fmt.Errorf(`task: Could not parse watch interval "%s": %v`, watchInterval, err)
|
|
||||||
}
|
|
||||||
return v, nil
|
|
||||||
}
|
|
||||||
|
Reference in New Issue
Block a user