github.com/upcmd/up@v0.8.1-0.20230108151705-ad8b797bf04f/tests/functests/c0076.yml (about) 1 doc_meta: | 2 folder: vars 3 title: local vs reg global 4 head: | 5 Showcase that local var is only available in local runtime for that func, if you need to use it global runtime, you will need to use template func reg or reg cmd to set it in global runtime 6 7 sections: 8 - title: Prerequisites 9 content: | 10 * template reg action 11 * reg cmd 12 refs: 13 - title: template reg action 14 link: ../../template/c0042/ 15 - title: reg cmd 16 link: ../../cmd-func/c0066/ 17 18 - title: Demo 19 log: yes 20 21 related: 22 refs: 23 - title: default golang template reference 24 link: https://golang.org/pkg/text/template/ 25 26 tasks: 27 28 - 29 name: task 30 desc: test the exit scenarios due to different types of validation 31 task: 32 - 33 func: shell 34 desc: step1 35 do: 36 - echo hanks 37 38 - 39 func: cmd 40 desc: | 41 test register a variable to global vars 42 the reg_hello should be <no value> since this is a template action 43 you should really use dvar name void instead 44 dvars: 45 - name: reg_hello 46 value: | 47 {{.last_result.Output |reg "hellomsg" }} 48 49 - 50 func: shell 51 do: 52 - echo "{{.reg_hello}}" 53 - echo "{{.hellomsg}}" 54 55 - 56 func: cmd 57 desc: | 58 the reg_tom's value is a object, but since reg_tom is only a local, it 59 will probably not very useful 60 vars: 61 person: 62 name: tom 63 age: 18 64 dvars: 65 - name: local_tom 66 value: |- 67 my name is tom 68 {{.person |reg "tom" }} 69 flags: [vvv] 70 do: 71 - name: reg 72 cmd: 73 name: global_tom 74 value: '{{.local_tom}}' 75 76 - 77 func: cmd 78 desc: debug the results 79 vars: 80 objname: global_tom 81 do: 82 - name: print 83 desc: this local_tom should be <no value> as it is in scope of last step 84 cmd: "{{.local_tom}}" 85 86 - name: print 87 desc: get the object from register global space 88 cmd: "{{.tom}}" 89 90 - name: printObj 91 desc: "dynamically reference to global_tom object registered" 92 cmd: "{{.objname}}" 93