diff --git a/CHANGELOG.md b/CHANGELOG.md index fe311987..3ab8562e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## Unreleased +- Added ability to set a different watch interval by setting + `interval: '500ms'` or using the `--interval=500ms` flag + ([#813](https://github.com/go-task/task/issues/813), [#865](https://github.com/go-task/task/pull/865)). - Add colored output to `--list`, `--list-all` and `--summary` flags ([#845](https://github.com/go-task/task/pull/845), [#874](https://github.com/go-task/task/pull/874)). - Fix unexpected behavior where `label:` was being shown instead of the task name on `--list` diff --git a/cmd/task/task.go b/cmd/task/task.go index abee37dd..c7c25dee 100644 --- a/cmd/task/task.go +++ b/cmd/task/task.go @@ -209,10 +209,6 @@ func main() { e.InterceptInterruptSignals() } - if e.Interval == "" { - e.Interval = strings.TrimSpace(interval) - } - ctx := context.Background() if status { diff --git a/docs/docs/api_reference.md b/docs/docs/api_reference.md index e67b721a..5a10c700 100644 --- a/docs/docs/api_reference.md +++ b/docs/docs/api_reference.md @@ -30,6 +30,7 @@ variable | `-f` | `--force` | `bool` | `false` | Forces execution even when the task is up-to-date. | | `-h` | `--help` | `bool` | `false` | Shows Task usage. | | `-i` | `--init` | `bool` | `false` | Creates a new Taskfile.yaml in the current folder. | +| `-I` | `--interval` | `string` | `5s` | Sets a different watch interval when using `--watch`, the default being 5 seconds. This string should be a valid [Go Duration](https://pkg.go.dev/time#ParseDuration). | | `-l` | `--list` | `bool` | `false` | Lists tasks with description of current Taskfile. | | `-a` | `--list-all` | `bool` | `false` | Lists tasks with or without a description. | | `-o` | `--output` | `string` | Default set in the Taskfile or `intervealed` | Sets output style: [`interleaved`/`group`/`prefixed`]. | @@ -84,6 +85,7 @@ Some environment variables can be overriden to adjust Task behavior. | `method` | `string` | `checksum` | Default method in this Taskfile. Can be overriden in a task by task basis. Available options: `checksum`, `timestamp` and `none`. | | `silent` | `bool` | `false` | Default "silent" options for this Taskfile. If `false`, can be overidden with `true` in a task by task basis. | | `run` | `string` | `always` | Default "run" option for this Taskfile. Available options: `always`, `once` and `when_changed`. | +| `interval` | `string` | `5s` | Sets a different watch interval when using `--watch`, the default being 5 seconds. This string should be a valid [Go Duration](https://pkg.go.dev/time#ParseDuration). | | `vars` | [`map[string]Variable`](#variable) | | Global variables. | | `env` | [`map[string]Variable`](#variable) | | Global environment. | | `dotenv` | `[]string` | | A list of `.env` file paths to be parsed. | diff --git a/docs/docs/usage.md b/docs/docs/usage.md index a36f97e1..10f2eab3 100644 --- a/docs/docs/usage.md +++ b/docs/docs/usage.md @@ -1247,5 +1247,9 @@ With the flags `--watch` or `-w` task will watch for file changes and run the task again. This requires the `sources` attribute to be given, so task knows which files to watch. +The default watch interval is 5 seconds, but it's possible to change it by +either setting `interval: '500ms'` in the root of the Taskfile passing it +as an argument like `--interval=500ms`. + [gotemplate]: https://golang.org/pkg/text/template/ [minify]: https://github.com/tdewolff/minify/tree/master/cmd/minify diff --git a/task_test.go b/task_test.go index b66d8d48..96d5a4bb 100644 --- a/task_test.go +++ b/task_test.go @@ -1503,10 +1503,10 @@ Hello, World! assert.NoError(t, e.Setup()) buff.Reset() - err := os.MkdirAll(dir+"/src", 0755) + err := os.MkdirAll(filepathext.SmartJoin(dir, "src"), 0755) assert.NoError(t, err) - err = os.WriteFile(dir+"/src/a", []byte("test"), 0644) + err = os.WriteFile(filepathext.SmartJoin(dir, "src/a"), []byte("test"), 0644) if err != nil { t.Fatal(err) } @@ -1529,16 +1529,16 @@ Hello, World! }(ctx) time.Sleep(10 * time.Millisecond) - err = os.WriteFile(dir+"/src/a", []byte("test updated"), 0644) + err = os.WriteFile(filepathext.SmartJoin(dir, "src/a"), []byte("test updated"), 0644) if err != nil { t.Fatal(err) } - time.Sleep(70 * time.Millisecond) + time.Sleep(700 * time.Millisecond) cancel() assert.Equal(t, expectedOutput, strings.TrimSpace(buff.String())) buff.Reset() - err = os.RemoveAll(dir + "/.task") + err = os.RemoveAll(filepathext.SmartJoin(dir, ".task")) assert.NoError(t, err) - err = os.RemoveAll(dir + "/src") + err = os.RemoveAll(filepathext.SmartJoin(dir, "src")) assert.NoError(t, err) } diff --git a/testdata/watcher_interval/Taskfile.yaml b/testdata/watcher_interval/Taskfile.yaml index 2a1e16b8..110eff27 100644 --- a/testdata/watcher_interval/Taskfile.yaml +++ b/testdata/watcher_interval/Taskfile.yaml @@ -5,7 +5,7 @@ version: '3' vars: GREETING: Hello, World! -interval: "30ms" +interval: "500ms" tasks: default: diff --git a/watch.go b/watch.go index 60ac6aae..6af7dbc6 100644 --- a/watch.go +++ b/watch.go @@ -51,7 +51,8 @@ func (e *Executor) watchTasks(calls ...taskfile.Call) error { var err error watchInterval, err = parseWatchInterval(watchIntervalString) if err != nil { - e.Logger.Errf(logger.Red, "%v", err) + cancel() + return err } }