diff --git a/CHANGELOG.md b/CHANGELOG.md index e0d27642..7fc77295 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## Unreleased + +- Add new `--exit-code` (`-x`) flag that will pass-through the exit form the + command being ran + ([#755](https://github.com/go-task/task/pull/755)). + ## v3.12.1 - 2022-05-10 - Fixed bug where, on Windows, variables were ending with `\r` because we were diff --git a/cmd/task/task.go b/cmd/task/task.go index 3c0fc609..7b9c8202 100644 --- a/cmd/task/task.go +++ b/cmd/task/task.go @@ -218,13 +218,13 @@ func main() { if err := e.Run(ctx, calls...); err != nil { e.Logger.Errf(logger.Red, "%v", err) - code := 1 + if exitCode { - if tre, ok := err.(*task.TaskRunError); ok { - code = tre.ExitCode() + if err, ok := err.(*task.TaskRunError); ok { + os.Exit(err.ExitCode()) } } - os.Exit(code) + os.Exit(1) } } diff --git a/docs/docs/api_reference.md b/docs/docs/api_reference.md index a0437872..91ccc793 100644 --- a/docs/docs/api_reference.md +++ b/docs/docs/api_reference.md @@ -26,6 +26,7 @@ variable | `-C` | `--concurrency` | `int` | `0` | Limit number tasks to run concurrently. Zero means unlimited. | | `-d` | `--dir` | `string` | Working directory | Sets directory of execution. | | | `--dry` | `bool` | `false` | Compiles and prints tasks in the order that they would be run, without executing them. | +| `-x` | `--exit-code` | `bool` | `false` | Pass-through the exit code of the task command. | | `-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. | diff --git a/errors.go b/errors.go index e2aa16b0..e13ad9b3 100644 --- a/errors.go +++ b/errors.go @@ -3,6 +3,7 @@ package task import ( "errors" "fmt" + "mvdan.cc/sh/v3/interp" )