Skip to content

Commit

Permalink
feat: add support for single cmd task syntax (#1131)
Browse files Browse the repository at this point in the history
  • Loading branch information
timdp authored Jun 11, 2023
1 parent 59e99ca commit e2c1b3b
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 1 deletion.
4 changes: 4 additions & 0 deletions docs/static/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@
"description": "A list of commands to be executed.",
"$ref": "#/definitions/3/cmds"
},
"cmd": {
"description": "The command to be executed.",
"$ref": "#/definitions/3/cmd"
},
"deps": {
"description": "A list of dependencies of this task. Tasks defined here will run in parallel before this task.",
"type": "array",
Expand Down
12 changes: 12 additions & 0 deletions task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2013,6 +2013,18 @@ func TestSplitArgs(t *testing.T) {
assert.Equal(t, "3\n", buff.String())
}

func TestSingleCmdDep(t *testing.T) {
tt := fileContentTest{
Dir: "testdata/single_cmd_dep",
Target: "foo",
Files: map[string]string{
"foo.txt": "foo\n",
"bar.txt": "bar\n",
},
}
tt.Run(t)
}

func TestSilence(t *testing.T) {
var buff bytes.Buffer
e := task.Executor{
Expand Down
10 changes: 9 additions & 1 deletion taskfile/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ func (t *Task) UnmarshalYAML(node *yaml.Node) error {
case yaml.MappingNode:
var task struct {
Cmds []*Cmd
Cmd *Cmd
Deps []*Dep
Label string
Desc string
Expand Down Expand Up @@ -102,7 +103,14 @@ func (t *Task) UnmarshalYAML(node *yaml.Node) error {
if err := node.Decode(&task); err != nil {
return err
}
t.Cmds = task.Cmds
if task.Cmd != nil {
if task.Cmds != nil {
return fmt.Errorf("yaml: line %d: task cannot have both cmd and cmds", node.Line)
}
t.Cmds = []*Cmd{task.Cmd}
} else {
t.Cmds = task.Cmds
}
t.Deps = task.Deps
t.Label = task.Label
t.Desc = task.Desc
Expand Down
1 change: 1 addition & 0 deletions testdata/single_cmd_dep/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.txt
8 changes: 8 additions & 0 deletions testdata/single_cmd_dep/Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: "3"

tasks:
foo:
deps: [bar]
cmd: echo foo > foo.txt

bar: echo bar > bar.txt

0 comments on commit e2c1b3b

Please sign in to comment.