File tree Expand file tree Collapse file tree 5 files changed +62
-11
lines changed Expand file tree Collapse file tree 5 files changed +62
-11
lines changed Original file line number Diff line number Diff line change @@ -1062,8 +1062,8 @@ task: [task-2] echo 'failing' && exit 2
1062
1062
failing
1063
1063
task: [task-2] echo 'echo ran'
1064
1064
echo ran
1065
- task: [task-1] echo 'task-1 ran'
1066
- task-1 ran
1065
+ task: [task-1] echo 'task-1 ran successfully '
1066
+ task-1 ran successfully
1067
1067
` )
1068
1068
assert .Error (t , e .Run (context .Background (), taskfile.Call {Task : "task-2" }))
1069
1069
fmt .Println (buff .String ())
Original file line number Diff line number Diff line change @@ -39,11 +39,19 @@ func (c *Cmd) UnmarshalYAML(unmarshal func(interface{}) error) error {
39
39
}
40
40
if err := unmarshal (& deferredCmd ); err == nil && deferredCmd .Defer != "" {
41
41
c .Defer = true
42
- if strings .HasPrefix (deferredCmd .Defer , "^" ) {
43
- c .Task = strings .TrimPrefix (deferredCmd .Defer , "^" )
44
- } else {
45
- c .Cmd = deferredCmd .Defer
42
+ c .Cmd = deferredCmd .Defer
43
+ return nil
44
+ }
45
+ var deferredCall struct {
46
+ Defer struct {
47
+ Task string
48
+ Vars * Vars
46
49
}
50
+ }
51
+ if err := unmarshal (& deferredCall ); err == nil && deferredCall .Defer .Task != "" {
52
+ c .Defer = true
53
+ c .Task = deferredCall .Defer .Task
54
+ c .Vars = deferredCall .Defer .Vars
47
55
return nil
48
56
}
49
57
var taskCall struct {
Original file line number Diff line number Diff line change
1
+ package taskfile
2
+
3
+ // Defer is the parameters to a defer operation.
4
+ // It can be exactly one of:
5
+ // - A string command
6
+ // - A task call
7
+ type Defer struct {
8
+ Cmd string
9
+ Call * Call
10
+ }
11
+
12
+ // isValid returns true when Defer describes a valid action.
13
+ // In order for a Defer to be valid, one of Cmd or Call.Task
14
+ // must be non-empty.
15
+ func (d * Defer ) isValid () bool {
16
+ return d .Cmd != "" || (d .Call != nil && d .Call .Task != "" )
17
+ }
18
+
19
+ // UnmarshalYAML implements yaml.Unmarshaler interface
20
+ func (d * Defer ) UnmarshalYAML (unmarshal func (interface {}) error ) error {
21
+ var cmd string
22
+ if err := unmarshal (& cmd ); err == nil {
23
+ d .Cmd = cmd
24
+ return nil
25
+ }
26
+ var taskCall struct {
27
+ Task string
28
+ Vars * Vars
29
+ }
30
+ if err := unmarshal (& taskCall ); err != nil {
31
+ return err
32
+ }
33
+ d .Call = & Call {
34
+ Task : taskCall .Task ,
35
+ Vars : taskCall .Vars ,
36
+ }
37
+ return nil
38
+ }
Original file line number Diff line number Diff line change 19
19
PARAM1: VALUE1
20
20
PARAM2: VALUE2
21
21
`
22
- yamlDeferredTask = `defer: ^ some_task`
22
+ yamlDeferredCall = `defer: { task: some_task, vars: { PARAM1: "var" } } `
23
23
yamlDeferredCmd = `defer: echo 'test'`
24
24
)
25
25
tests := []struct {
49
49
& taskfile.Cmd {Cmd : "echo 'test'" , Defer : true },
50
50
},
51
51
{
52
- yamlDeferredTask ,
52
+ yamlDeferredCall ,
53
53
& taskfile.Cmd {},
54
- & taskfile.Cmd {Task : "some_task" , Defer : true },
54
+ & taskfile.Cmd {Task : "some_task" , Vars : & taskfile.Vars {
55
+ Keys : []string {"PARAM1" },
56
+ Mapping : map [string ]taskfile.Var {
57
+ "PARAM1" : taskfile.Var {Static : "var" },
58
+ },
59
+ }, Defer : true },
55
60
},
56
61
{
57
62
yamlDep ,
Original file line number Diff line number Diff line change @@ -2,10 +2,10 @@ version: "3"
2
2
3
3
tasks :
4
4
task-1 :
5
- - echo 'task-1 ran'
5
+ - echo 'task-1 ran {{.PARAM}} '
6
6
7
7
task-2 :
8
- - defer : " ^ task-1"
8
+ - defer : { task: " task-1", vars: { PARAM: "successfully" } }
9
9
- defer : echo 'echo ran'
10
10
- defer : echo 'failing' && exit 2
11
11
- echo 'cmd ran'
You can’t perform that action at this time.
0 commit comments