-
Notifications
You must be signed in to change notification settings - Fork 4
/
c0113.yml
95 lines (81 loc) · 2.73 KB
/
c0113.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
doc_meta: |
folder: call-func
title: return values
head: |
As we know you will actually implicitly creaet a whole private call stack and spawn a private local vars in this scope, in such a case the work you have done, including register some values to global(relatively to this private stack), will not be reflected in your caller's var scope. So how do you keep your result in case that you really need to do so.
We can use return cmd to achieve that. When you use return cmd, all the listed var names' values will be registered to its caller's var scope
sections:
- title: Demo
log: yes
notes:
goal:
- add new feature of return from callee task
- |
application could be use as auto returned vars to parent var scope,
or use as a callerable task module to do a callback data injection
for other client caller tasks
- notice the difference between c0107 and this case
vars:
tom: this is tom in global
jerry: this is jerry in global
tasks:
-
name: task
desc: main entry
task:
-
func: call
desc: call subtask and exam the return value in following steps
do: subtask
-
func: cmd
desc: check value of tom
do:
- name: print
cmd: 'in main task print3: {{.tom}}'
-
name: assert
desc: since .tom is returned from callee, it should be accessible here
cmd:
- '{{eq .tom "tom created in sub_loop"}}'
-
name: subtask
desc: subtask to test reg and return
task:
-
func: cmd
desc: check value of tom after it is registered in current task stack
vars:
john: john in sub_loop func1
do:
- name: reg
desc: by default hitom is registered in to global context
cmd:
name: tom
value: 'tom created in sub_loop'
- name: print
cmd: 'in sub_loop print1: {{.tom}}'
-
name: assert
cmd:
- '{{eq .tom "tom created in sub_loop"}}'
-
func: cmd
desc: check value of tom and it should be available in current stack
vars:
john: john in sub_loop func2
do:
- name: print
cmd: 'in sub_loop print2: {{.tom}}'
-
name: assert
desc: since .tom is in callee's global, it should be accessible here
cmd:
- '{{eq .tom "tom created in sub_loop"}}'
- name: return
desc: |
it should return and merge tom to parent's vars scope
it should report warning as jason does not exist
cmd:
- tom
- jason