Move all structs related to Taskfile to its own package

This commit is contained in:
Andrey Nering
2018-02-17 14:22:18 -02:00
parent 3212ae4713
commit 152fc0ad38
16 changed files with 223 additions and 203 deletions

View File

@@ -4,7 +4,7 @@ import (
"errors"
"strings"
"github.com/go-task/task"
"github.com/go-task/task/internal/taskfile"
)
var (
@@ -13,12 +13,12 @@ var (
)
// Parse parses command line argument: tasks and vars of each task
func Parse(args ...string) ([]task.Call, error) {
var calls []task.Call
func Parse(args ...string) ([]taskfile.Call, error) {
var calls []taskfile.Call
for _, arg := range args {
if !strings.Contains(arg, "=") {
calls = append(calls, task.Call{Task: arg})
calls = append(calls, taskfile.Call{Task: arg})
continue
}
if len(calls) < 1 {
@@ -26,11 +26,11 @@ func Parse(args ...string) ([]task.Call, error) {
}
if calls[len(calls)-1].Vars == nil {
calls[len(calls)-1].Vars = make(task.Vars)
calls[len(calls)-1].Vars = make(taskfile.Vars)
}
pair := strings.SplitN(arg, "=", 2)
calls[len(calls)-1].Vars[pair[0]] = task.Var{Static: pair[1]}
calls[len(calls)-1].Vars[pair[0]] = taskfile.Var{Static: pair[1]}
}
return calls, nil
}

View File

@@ -4,8 +4,8 @@ import (
"fmt"
"testing"
"github.com/go-task/task"
"github.com/go-task/task/internal/args"
"github.com/go-task/task/internal/taskfile"
"github.com/stretchr/testify/assert"
)
@@ -13,12 +13,12 @@ import (
func TestArgs(t *testing.T) {
tests := []struct {
Args []string
Expected []task.Call
Expected []taskfile.Call
Err error
}{
{
Args: []string{"task-a", "task-b", "task-c"},
Expected: []task.Call{
Expected: []taskfile.Call{
{Task: "task-a"},
{Task: "task-b"},
{Task: "task-c"},
@@ -26,30 +26,30 @@ func TestArgs(t *testing.T) {
},
{
Args: []string{"task-a", "FOO=bar", "task-b", "task-c", "BAR=baz", "BAZ=foo"},
Expected: []task.Call{
Expected: []taskfile.Call{
{
Task: "task-a",
Vars: task.Vars{
"FOO": task.Var{Static: "bar"},
Vars: taskfile.Vars{
"FOO": taskfile.Var{Static: "bar"},
},
},
{Task: "task-b"},
{
Task: "task-c",
Vars: task.Vars{
"BAR": task.Var{Static: "baz"},
"BAZ": task.Var{Static: "foo"},
Vars: taskfile.Vars{
"BAR": taskfile.Var{Static: "baz"},
"BAZ": taskfile.Var{Static: "foo"},
},
},
},
},
{
Args: []string{"task-a", "CONTENT=with some spaces"},
Expected: []task.Call{
Expected: []taskfile.Call{
{
Task: "task-a",
Vars: task.Vars{
"CONTENT": task.Var{Static: "with some spaces"},
Vars: taskfile.Vars{
"CONTENT": taskfile.Var{Static: "with some spaces"},
},
},
},