-
Notifications
You must be signed in to change notification settings - Fork 4
/
c0072.yml
113 lines (90 loc) · 2.9 KB
/
c0072.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
doc_meta: |
folder: templating
title: use template cmd
head: |
Showcase use template cmd to template
sections:
- title: my story text file reference
filelookup: d0072.template
- title: How to use?
content: |
By default, all the vars from within the template will be substituted from the vars
It also demos that the rendered result could be a dynamic variable which pointing to a filename
- title: Demo a use env var as input to determine working dir
content: |
This demos that if GOTEST env variable is set, then load the file from testing directory or root dir
- title: Demo
log: yes
notes:
goal:
- add cmd template as a shortcut to render file
- test case shows that you can use vars in src and dest
vars:
name: little prince
school: sydney grammar
age: 12
said: Boa constrictors swallow their prey whole
save_to: /tmp/mystory2.txt
read_dir: /tmp
read_file: mystory2.txt
dvars:
- name: intest
value: '{{ env "GOTEST" |default "false" }}'
tasks:
- name: task
task:
- func: shell
do:
- echo "?intest -> {{.intest}}"
- pwd
reg: register_task_root
- func: cmd
do:
- name: print
cmd: 'intest is: [{{.intest}}]'
- name: reg
cmd:
name: correct_working_dir
desc: the value of .intest is string but not bool so you can not simply use if .intest for condition
value: >-
{{if eq .intest "true" }}{{.register_task_root.Output}}{{else}}{{.register_task_root.Output}}{{end}}
- func: cmd
do:
- name: print
cmd: 'root dir is: [{{.register_task_root.Output}}]'
- name: print
cmd: 'correct working dir is: [{{.correct_working_dir}}]'
-
name: template
desc: render a template file to a file 1
cmd:
src: '{{.correct_working_dir}}/tests/functests/d0072.template'
dest: /tmp/mystory.txt
-
name: readFile
desc: read content of a file and register it to a var
cmd:
filename: mystory.txt
dir: /tmp
reg: my_interesting_story
-
name: print
cmd: "{{.my_interesting_story}}"
- func: cmd
do:
-
name: template
desc: render a template file to a file 2
cmd:
src: '{{.correct_working_dir}}/tests/functests/d0072.template'
dest: '{{.save_to}}'
-
name: readFile
desc: read content of a file and register it to a var
cmd:
filename: '{{.read_file}}'
dir: '{{.read_dir}}'
reg: my_interesting_story2
-
name: print
cmd: "{{.my_interesting_story2}}"