From a4685229c96bf695fabb3fb031be7634a3a7f6c2 Mon Sep 17 00:00:00 2001 From: Andrey Nering Date: Sat, 7 Dec 2019 16:20:36 -0300 Subject: [PATCH] Fix bug of Task not executing the "default" task When global vars were informed using the CLI. I took the oportunity to move this logic to the proper package and write a test. --- CHANGELOG.md | 2 ++ cmd/task/task.go | 8 +------- internal/args/args.go | 4 ++++ internal/args/args_test.go | 10 ++++++++++ 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e696199a..b0170058 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ - Add `--parallel` flag (alias `-p`) to run tasks given by the command line in parallel ([#266](https://github.com/go-task/task/pull/266)). +- Fixed bug where calling the `task` CLI only informing global vars would not + execute the `default` task. ## v2.7.1 - 2019-11-10 diff --git a/cmd/task/task.go b/cmd/task/task.go index 3ae8dcd8..c791ff39 100644 --- a/cmd/task/task.go +++ b/cmd/task/task.go @@ -133,13 +133,7 @@ func main() { return } - arguments := pflag.Args() - if len(arguments) == 0 { - log.Println("task: No argument given, trying default task") - arguments = []string{"default"} - } - - calls, globals := args.Parse(arguments...) + calls, globals := args.Parse(pflag.Args()...) for name, value := range globals { e.Taskfile.Vars[name] = value } diff --git a/internal/args/args.go b/internal/args/args.go index 0993e549..acea9c29 100644 --- a/internal/args/args.go +++ b/internal/args/args.go @@ -34,6 +34,10 @@ func Parse(args ...string) ([]taskfile.Call, taskfile.Vars) { } } + if len(calls) == 0 { + calls = append(calls, taskfile.Call{Task: "default"}) + } + return calls, globals } diff --git a/internal/args/args_test.go b/internal/args/args_test.go index 137c23e3..7357acdd 100644 --- a/internal/args/args_test.go +++ b/internal/args/args_test.go @@ -64,6 +64,16 @@ func TestArgs(t *testing.T) { "FOO": {Static: "bar"}, }, }, + { + Args: []string{"FOO=bar", "BAR=baz"}, + ExpectedCalls: []taskfile.Call{ + {Task: "default"}, + }, + ExpectedGlobals: taskfile.Vars{ + "FOO": {Static: "bar"}, + "BAR": {Static: "baz"}, + }, + }, } for i, test := range tests {