This shows that you can use datakey and datapath to reference to a varname and a sub element of a var in global runtime scope
the datakey would be a plain text of a var name, or a dynamic templating value to pointing to a var name
datapath: format is like a.b.c(name=fr*).value, following the yq path format:
render using dvar and datakey
query details
vars:
school_details_object:
school:
name: "sydney grammar"
address: "1 fox road, sydney, nsw 2000"
principals:
- "peter"
- "tom"
- "jane"
ranking: "No 5"
root:
parent:
school_details_object:
school:
name: "sydney grammar"
address: "1 fox road, sydney, nsw 2000"
principals:
- "peter"
- "tom"
- "jane"
ranking: "No 5"
tasks:
- name: task
task:
- func: cmd
do:
- name: template
desc: render the template file using above dynamic variable from defined var
cmd:
src: './tests/functests/d0079.template'
dest: /tmp/myschool.txt
datakey: "school_details_object"
- func: cmd
do:
- name: readFile
desc: read content of a file and register it to a var
cmd:
filename: myschool.txt
dir: /tmp
reg: my_school
- name: print
cmd: "{{.my_school}}"
- func: cmd
do:
- name: template
desc: render the template file using above dynamic variable from defined var
cmd:
src: './tests/functests/d0079.template'
dest: /tmp/myschool.txt
datapath: "root.parent.school_details_object"
- func: cmd
do:
- name: readFile
desc: read content of a file and register it to a var
cmd:
filename: myschool.txt
dir: /tmp
reg: my_school
- name: print
cmd: "{{.my_school}}"
loading [Config]: ./tests/functests/upconfig.yml
Main config:
Version -> 1.0.0
RefDir -> ./tests/functests
WorkDir -> cwd
AbsWorkDir -> /up_project/up
TaskFile -> c0096
Verbose -> vvv
ModuleName -> self
ShellType -> /bin/sh
MaxCallLayers -> 8
Timeout -> 3600000
MaxModuelCallLayers -> 256
EntryTask -> task
ModRepoUsernameRef ->
ModRepoPasswordRef ->
work dir: /up_project/up
-exec task: task
loading [Task]: ./tests/functests/c0096
module: [self], instance id: [dev], exec profile: []
profile - envVars:
(*core.Cache)({
})
Task1: [task ==> task: ]
-Step1:
self: final context exec vars:
(*core.Cache)({
"root": {
"parent": {
"school_details_object": {
"ranking": "No 5",
"school": {
"name": "sydney grammar",
"address": "1 fox road, sydney, nsw 2000"
},
"principals": {
"peter",
"tom",
"jane"
}
}
}
},
"up_runtime_task_layer_number": 0,
"school_details_object": {
"school": {
"address": "1 fox road, sydney, nsw 2000",
"name": "sydney grammar"
},
"principals": {
"peter",
"tom",
"jane"
},
"ranking": "No 5"
}
})
~SubStep1: [template: render the template file using above dynamic variable from defined var ]
-Step2:
self: final context exec vars:
(*core.Cache)({
"up_runtime_task_layer_number": 0,
"school_details_object": {
"ranking": "No 5",
"school": {
"name": "sydney grammar",
"address": "1 fox road, sydney, nsw 2000"
},
"principals": {
"peter",
"tom",
"jane"
}
},
"root": {
"parent": {
"school_details_object": {
"principals": {
"peter",
"tom",
"jane"
},
"ranking": "No 5",
"school": {
"name": "sydney grammar",
"address": "1 fox road, sydney, nsw 2000"
}
}
}
}
})
~SubStep1: [readFile: read content of a file and register it to a var ]
~SubStep2: [print: ]
My school name is: sydney grammar, it is located
at 1 fox road, sydney, nsw 2000
We have got peter, tom, jane, as our principals
Our school ranking last year is No 5
-Step3:
self: final context exec vars:
(*core.Cache)({
"my_school": "\n\nMy school name is: sydney grammar, it is located\nat 1 fox road, sydney, nsw 2000\n\n\nWe have got peter, tom, jane, as our principals\n\nOur school ranking last year is No 5\n",
"school_details_object": {
"school": {
"name": "sydney grammar",
"address": "1 fox road, sydney, nsw 2000"
},
"principals": {
"peter",
"tom",
"jane"
},
"ranking": "No 5"
},
"root": {
"parent": {
"school_details_object": {
"school": {
"name": "sydney grammar",
"address": "1 fox road, sydney, nsw 2000"
},
"principals": {
"peter",
"tom",
"jane"
},
"ranking": "No 5"
}
}
},
"up_runtime_task_layer_number": 0
})
~SubStep1: [template: render the template file using above dynamic variable from defined var ]
-Step4:
self: final context exec vars:
(*core.Cache)({
"my_school": "\n\nMy school name is: sydney grammar, it is located\nat 1 fox road, sydney, nsw 2000\n\n\nWe have got peter, tom, jane, as our principals\n\nOur school ranking last year is No 5\n",
"up_runtime_task_layer_number": 0,
"school_details_object": {
"school": {
"name": "sydney grammar",
"address": "1 fox road, sydney, nsw 2000"
},
"principals": {
"peter",
"tom",
"jane"
},
"ranking": "No 5"
},
"root": {
"parent": {
"school_details_object": {
"school": {
"name": "sydney grammar",
"address": "1 fox road, sydney, nsw 2000"
},
"principals": {
"peter",
"tom",
"jane"
},
"ranking": "No 5"
}
}
}
})
~SubStep1: [readFile: read content of a file and register it to a var ]
~SubStep2: [print: ]
My school name is: sydney grammar, it is located
at 1 fox road, sydney, nsw 2000
We have got peter, tom, jane, as our principals
Our school ranking last year is No 5