Skip to content

Commit a468522

Browse files
committed
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.
1 parent f0bc4d2 commit a468522

File tree

4 files changed

+17
-7
lines changed

4 files changed

+17
-7
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
- Add `--parallel` flag (alias `-p`) to run tasks given by the command line in
66
parallel
77
([#266](https://github.com/go-task/task/pull/266)).
8+
- Fixed bug where calling the `task` CLI only informing global vars would not
9+
execute the `default` task.
810

911
## v2.7.1 - 2019-11-10
1012

cmd/task/task.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,7 @@ func main() {
133133
return
134134
}
135135

136-
arguments := pflag.Args()
137-
if len(arguments) == 0 {
138-
log.Println("task: No argument given, trying default task")
139-
arguments = []string{"default"}
140-
}
141-
142-
calls, globals := args.Parse(arguments...)
136+
calls, globals := args.Parse(pflag.Args()...)
143137
for name, value := range globals {
144138
e.Taskfile.Vars[name] = value
145139
}

internal/args/args.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ func Parse(args ...string) ([]taskfile.Call, taskfile.Vars) {
3434
}
3535
}
3636

37+
if len(calls) == 0 {
38+
calls = append(calls, taskfile.Call{Task: "default"})
39+
}
40+
3741
return calls, globals
3842
}
3943

internal/args/args_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,16 @@ func TestArgs(t *testing.T) {
6464
"FOO": {Static: "bar"},
6565
},
6666
},
67+
{
68+
Args: []string{"FOO=bar", "BAR=baz"},
69+
ExpectedCalls: []taskfile.Call{
70+
{Task: "default"},
71+
},
72+
ExpectedGlobals: taskfile.Vars{
73+
"FOO": {Static: "bar"},
74+
"BAR": {Static: "baz"},
75+
},
76+
},
6777
}
6878

6979
for i, test := range tests {

0 commit comments

Comments
 (0)