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:
parent
59e99caf8a
commit
e2c1b3b931
4
docs/static/schema.json
vendored
4
docs/static/schema.json
vendored
@ -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",
|
||||
|
12
task_test.go
12
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{
|
||||
|
@ -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
1
testdata/single_cmd_dep/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
*.txt
|
8
testdata/single_cmd_dep/Taskfile.yml
vendored
Normal file
8
testdata/single_cmd_dep/Taskfile.yml
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
version: "3"
|
||||
|
||||
tasks:
|
||||
foo:
|
||||
deps: [bar]
|
||||
cmd: echo foo > foo.txt
|
||||
|
||||
bar: echo bar > bar.txt
|
Loading…
x
Reference in New Issue
Block a user