diff --git a/docs/static/schema.json b/docs/static/schema.json index 8e15219e11..8a82d83f6c 100644 --- a/docs/static/schema.json +++ b/docs/static/schema.json @@ -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", diff --git a/task_test.go b/task_test.go index e76dc1a012..8ea91d2a0f 100644 --- a/task_test.go +++ b/task_test.go @@ -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{ diff --git a/taskfile/task.go b/taskfile/task.go index 04ed6f1e97..f82ced19b2 100644 --- a/taskfile/task.go +++ b/taskfile/task.go @@ -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 @@ -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 diff --git a/testdata/single_cmd_dep/.gitignore b/testdata/single_cmd_dep/.gitignore new file mode 100644 index 0000000000..2211df63dd --- /dev/null +++ b/testdata/single_cmd_dep/.gitignore @@ -0,0 +1 @@ +*.txt diff --git a/testdata/single_cmd_dep/Taskfile.yml b/testdata/single_cmd_dep/Taskfile.yml new file mode 100644 index 0000000000..3023d2b1b5 --- /dev/null +++ b/testdata/single_cmd_dep/Taskfile.yml @@ -0,0 +1,8 @@ +version: "3" + +tasks: + foo: + deps: [bar] + cmd: echo foo > foo.txt + + bar: echo bar > bar.txt