github.com/upcmd/up@v0.8.1-0.20230108151705-ad8b797bf04f/tests/functests/c0072.yml (about) 1 doc_meta: | 2 folder: templating 3 title: use template cmd 4 head: | 5 Showcase use template cmd to template 6 7 sections: 8 - title: my story text file reference 9 filelookup: d0072.template 10 11 - title: How to use? 12 content: | 13 By default, all the vars from within the template will be substituted from the vars 14 15 It also demos that the rendered result could be a dynamic variable which pointing to a filename 16 17 - title: Demo a use env var as input to determine working dir 18 content: | 19 This demos that if GOTEST env variable is set, then load the file from testing directory or root dir 20 21 - title: Demo 22 log: yes 23 24 25 notes: 26 goal: 27 - add cmd template as a shortcut to render file 28 - test case shows that you can use vars in src and dest 29 30 vars: 31 name: little prince 32 school: sydney grammar 33 age: 12 34 said: Boa constrictors swallow their prey whole 35 save_to: /tmp/mystory2.txt 36 read_dir: /tmp 37 read_file: mystory2.txt 38 39 dvars: 40 - name: intest 41 value: '{{ env "GOTEST" |default "false" }}' 42 43 tasks: 44 45 - name: task 46 task: 47 - func: shell 48 do: 49 - echo "?intest -> {{.intest}}" 50 - pwd 51 reg: register_task_root 52 53 - func: cmd 54 do: 55 - name: print 56 cmd: 'intest is: [{{.intest}}]' 57 58 - name: reg 59 cmd: 60 name: correct_working_dir 61 desc: the value of .intest is string but not bool so you can not simply use if .intest for condition 62 value: >- 63 {{if eq .intest "true" }}{{.register_task_root.Output}}{{else}}{{.register_task_root.Output}}{{end}} 64 65 - func: cmd 66 do: 67 - name: print 68 cmd: 'root dir is: [{{.register_task_root.Output}}]' 69 70 - name: print 71 cmd: 'correct working dir is: [{{.correct_working_dir}}]' 72 73 - 74 name: template 75 desc: render a template file to a file 1 76 cmd: 77 src: '{{.correct_working_dir}}/tests/functests/d0072.template' 78 dest: /tmp/mystory.txt 79 80 - 81 name: readFile 82 desc: read content of a file and register it to a var 83 cmd: 84 filename: mystory.txt 85 dir: /tmp 86 reg: my_interesting_story 87 88 - 89 name: print 90 cmd: "{{.my_interesting_story}}" 91 92 - func: cmd 93 do: 94 95 - 96 name: template 97 desc: render a template file to a file 2 98 cmd: 99 src: '{{.correct_working_dir}}/tests/functests/d0072.template' 100 dest: '{{.save_to}}' 101 102 - 103 name: readFile 104 desc: read content of a file and register it to a var 105 cmd: 106 filename: '{{.read_file}}' 107 dir: '{{.read_dir}}' 108 reg: my_interesting_story2 109 110 - 111 name: print 112 cmd: "{{.my_interesting_story2}}" 113