initial pass at deferred commands

This commit is contained in:
Jacob McCollum
2021-12-15 00:03:37 -05:00
parent 1c782c599f
commit 69e9effc88
6 changed files with 78 additions and 0 deletions

View File

@@ -7,6 +7,7 @@ type Cmd struct {
Task string
Vars *Vars
IgnoreError bool
Defer bool
}
// Dep is a task dependency
@@ -33,6 +34,18 @@ func (c *Cmd) UnmarshalYAML(unmarshal func(interface{}) error) error {
c.IgnoreError = cmdStruct.IgnoreError
return nil
}
var deferredCmd struct {
Defer string
}
if err := unmarshal(&deferredCmd); err == nil && deferredCmd.Defer != "" {
c.Defer = true
if strings.HasPrefix(deferredCmd.Defer, "^") {
c.Task = strings.TrimPrefix(deferredCmd.Defer, "^")
} else {
c.Cmd = deferredCmd.Defer
}
return nil
}
var taskCall struct {
Task string
Vars *Vars

View File

@@ -19,6 +19,8 @@ vars:
PARAM1: VALUE1
PARAM2: VALUE2
`
yamlDeferredTask = `defer: ^some_task`
yamlDeferredCmd = `defer: echo 'test'`
)
tests := []struct {
content string
@@ -41,6 +43,16 @@ vars:
},
}},
},
{
yamlDeferredCmd,
&taskfile.Cmd{},
&taskfile.Cmd{Cmd: "echo 'test'", Defer: true},
},
{
yamlDeferredTask,
&taskfile.Cmd{},
&taskfile.Cmd{Task: "some_task", Defer: true},
},
{
yamlDep,
&taskfile.Dep{},