1
0
mirror of https://github.com/go-task/task.git synced 2025-05-31 23:19:42 +02:00

feat: add support for single cmd task syntax (#1131)

This commit is contained in:
Tim De Pauw 2023-06-11 03:08:28 +02:00 committed by GitHub
parent 59e99caf8a
commit e2c1b3b931
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 34 additions and 1 deletions

View File

@ -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",

View File

@ -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{

View File

@ -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

1
testdata/single_cmd_dep/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*.txt

8
testdata/single_cmd_dep/Taskfile.yml vendored Normal file
View File

@ -0,0 +1,8 @@
version: "3"
tasks:
foo:
deps: [bar]
cmd: echo foo > foo.txt
bar: echo bar > bar.txt