Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: --download by itself will not run a task
  • Loading branch information
pd93 committed Sep 4, 2023
commit 69871ddf7f67408674decb52cae6b9c8664d2f79
12 changes: 2 additions & 10 deletions args/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

// ParseV3 parses command line argument: tasks and global variables
func ParseV3(args ...string) ([]taskfile.Call, *taskfile.Vars) {
var calls []taskfile.Call
calls := []taskfile.Call{}
globals := &taskfile.Vars{}

for _, arg := range args {
Expand All @@ -21,16 +21,12 @@ func ParseV3(args ...string) ([]taskfile.Call, *taskfile.Vars) {
globals.Set(name, taskfile.Var{Static: value})
}

if len(calls) == 0 {
calls = append(calls, taskfile.Call{Task: "default", Direct: true})
}

return calls, globals
}

// ParseV2 parses command line argument: tasks and vars of each task
func ParseV2(args ...string) ([]taskfile.Call, *taskfile.Vars) {
var calls []taskfile.Call
calls := []taskfile.Call{}
globals := &taskfile.Vars{}

for _, arg := range args {
Expand All @@ -51,10 +47,6 @@ func ParseV2(args ...string) ([]taskfile.Call, *taskfile.Vars) {
}
}

if len(calls) == 0 {
calls = append(calls, taskfile.Call{Task: "default", Direct: true})
}

return calls, globals
}

Expand Down
36 changes: 12 additions & 24 deletions args/args_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,16 @@ func TestArgsV3(t *testing.T) {
},
},
{
Args: nil,
ExpectedCalls: []taskfile.Call{
{Task: "default", Direct: true},
},
Args: nil,
ExpectedCalls: []taskfile.Call{},
},
{
Args: []string{},
ExpectedCalls: []taskfile.Call{
{Task: "default", Direct: true},
},
Args: []string{},
ExpectedCalls: []taskfile.Call{},
},
{
Args: []string{"FOO=bar", "BAR=baz"},
ExpectedCalls: []taskfile.Call{
{Task: "default", Direct: true},
},
Args: []string{"FOO=bar", "BAR=baz"},
ExpectedCalls: []taskfile.Call{},
ExpectedGlobals: &taskfile.Vars{
OrderedMap: orderedmap.FromMapWithOrder(
map[string]taskfile.Var{
Expand Down Expand Up @@ -191,22 +185,16 @@ func TestArgsV2(t *testing.T) {
},
},
{
Args: nil,
ExpectedCalls: []taskfile.Call{
{Task: "default", Direct: true},
},
Args: nil,
ExpectedCalls: []taskfile.Call{},
},
{
Args: []string{},
ExpectedCalls: []taskfile.Call{
{Task: "default", Direct: true},
},
Args: []string{},
ExpectedCalls: []taskfile.Call{},
},
{
Args: []string{"FOO=bar", "BAR=baz"},
ExpectedCalls: []taskfile.Call{
{Task: "default", Direct: true},
},
Args: []string{"FOO=bar", "BAR=baz"},
ExpectedCalls: []taskfile.Call{},
ExpectedGlobals: &taskfile.Vars{
OrderedMap: orderedmap.FromMapWithOrder(
map[string]taskfile.Var{
Expand Down
7 changes: 7 additions & 0 deletions cmd/task/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,13 @@ func run() error {
calls, globals = args.ParseV2(tasksAndVars...)
}

// If there are no calls, run the default task instead
// Unless the download flag is specified, in which case we want to download
// the Taskfile and do nothing else
if len(calls) == 0 && !flags.download {
calls = append(calls, taskfile.Call{Task: "default", Direct: true})
}

globals.Set("CLI_ARGS", taskfile.Var{Static: cliArgs})
e.Taskfile.Vars.Merge(globals)

Expand Down