splitLines func
Showcase the usage of splitLines func
Demo
source
Main task yaml file
vars:
workers:
- peter
- tom
- james
lines: |-
hello
this
is a
beautiful world
tasks:
- name: task
desc: generate logs
task:
- func: shell
dvars:
- name: linelist
desc: |
dvar value always return a string instead of object, if you
need to use the object, you will need to register it to global space
value: '{{ .lines | splitLines }}'
flags: [vvv]
do:
- echo '{{.lines}}'
- echo '{{.linelist}}'
- func: shell
dvars:
- name: linelist
value: '{{ .lines | splitLines | printObj }}'
flags: [vvv]
do:
- echo '{{.lines}}'
- echo '{{.linelist}}'
- func: shell
name: regtest
dvars:
- name: linelist
value: '{{ .lines | splitLines | reg "linelist_object" }}'
flags: [vvv]
do:
- echo '{{.lines}}'
- echo '{{.linelist}}'
- echo '{{.linelist_object}}'
- func: shell
loop: workers
do:
- echo "{{.loopindex1}} -> {{.loopitem}}"
- func: shell
loop: linelist_object
do:
- echo "{{.loopindex1}} -> {{.loopitem}}"
Main log file
loading [Config]: ./tests/functests/upconfig.yml
Main config:
Version -> 1.0.0
RefDir -> ./tests/functests
WorkDir -> cwd
AbsWorkDir -> /up_project/up
TaskFile -> c0085
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/c0085
module: [self], instance id: [dev], exec profile: []
profile - envVars:
(*core.Cache)({
})
Task1: [task ==> task: generate logs ]
-Step1:
dvar> linelist:
"[hello this is a beautiful world]"
-
[hello this is a beautiful world]
self: final context exec vars:
(*core.Cache)({
"up_runtime_task_layer_number": 0,
"linelist": "[hello this is a beautiful world]",
"workers": {
"peter",
"tom",
"james"
},
"lines": "hello\nthis\nis a\nbeautiful world"
})
cmd( 1):
echo '{{.lines}}'
-
hello
this
is a
beautiful world
-
.. ok
cmd( 2):
echo '{{.linelist}}'
-
[hello this is a beautiful world]
-
.. ok
. ok
-Step2:
{
"hello",
"this",
"is a",
"beautiful world"
}
dvar> linelist:
"{\n \"hello\",\n \"this\",\n \"is a\",\n \"beautiful world\"\n}\n\n"
-
{
"hello",
"this",
"is a",
"beautiful world"
}
self: final context exec vars:
(*core.Cache)({
"workers": {
"peter",
"tom",
"james"
},
"lines": "hello\nthis\nis a\nbeautiful world",
"up_runtime_task_layer_number": 0,
"linelist": "{\n \"hello\",\n \"this\",\n \"is a\",\n \"beautiful world\"\n}\n\n",
"last_result": (*utils.ExecResult)({
Cmd: "echo '[hello this is a beautiful world]'",
Code: 0,
Output: "[hello this is a beautiful world]",
ErrMsg: ""
})
})
cmd( 1):
echo '{{.lines}}'
-
hello
this
is a
beautiful world
-
.. ok
cmd( 2):
echo '{{.linelist}}'
-
{
"hello",
"this",
"is a",
"beautiful world"
}
-
.. ok
. ok
-Step3: [regtest: ]
dvar> linelist:
"- hello\n- this\n- is a\n- beautiful world\n"
-
- hello
- this
- is a
- beautiful world
self: final context exec vars:
(*core.Cache)({
"lines": "hello\nthis\nis a\nbeautiful world",
"up_runtime_task_layer_number": 0,
"linelist_object": {
"hello",
"this",
"is a",
"beautiful world"
},
"linelist": "- hello\n- this\n- is a\n- beautiful world\n",
"last_result": (*utils.ExecResult)({
Cmd: "echo '{\n \"hello\",\n \"this\",\n \"is a\",\n \"beautiful world\"\n}\n\n'",
Code: 0,
Output: "{\n \"hello\",\n \"this\",\n \"is a\",\n \"beautiful world\"\n}",
ErrMsg: ""
}),
"workers": {
"peter",
"tom",
"james"
}
})
cmd( 1):
echo '{{.lines}}'
-
hello
this
is a
beautiful world
-
.. ok
cmd( 2):
echo '{{.linelist}}'
-
- hello
- this
- is a
- beautiful world
-
.. ok
cmd( 3):
echo '{{.linelist_object}}'
-
[hello this is a beautiful world]
-
.. ok
. ok
-Step4:
self: final context exec vars:
(*core.Cache)({
"last_result": (*utils.ExecResult)({
Cmd: "echo '[hello this is a beautiful world]'",
Code: 0,
Output: "[hello this is a beautiful world]",
ErrMsg: ""
}),
"linelist_object": {
"hello",
"this",
"is a",
"beautiful world"
},
"up_runtime_task_layer_number": 0,
"workers": {
"peter",
"tom",
"james"
},
"lines": "hello\nthis\nis a\nbeautiful world"
})
cmd( 1):
echo "{{.loopindex1}} -> {{.loopitem}}"
-
1 -> peter
-
.. ok
cmd( 1):
echo "{{.loopindex1}} -> {{.loopitem}}"
-
2 -> tom
-
.. ok
cmd( 1):
echo "{{.loopindex1}} -> {{.loopitem}}"
-
3 -> james
-
.. ok
. ok
-Step5:
self: final context exec vars:
(*core.Cache)({
"lines": "hello\nthis\nis a\nbeautiful world",
"last_result": (*utils.ExecResult)({
Cmd: "echo \"3 -> james\"",
Code: 0,
Output: "3 -> james",
ErrMsg: ""
}),
"up_runtime_task_layer_number": 0,
"linelist_object": {
"hello",
"this",
"is a",
"beautiful world"
},
"workers": {
"peter",
"tom",
"james"
}
})
cmd( 1):
echo "{{.loopindex1}} -> {{.loopitem}}"
-
1 -> hello
-
.. ok
cmd( 1):
echo "{{.loopindex1}} -> {{.loopitem}}"
-
2 -> this
-
.. ok
cmd( 1):
echo "{{.loopindex1}} -> {{.loopitem}}"
-
3 -> is a
-
.. ok
cmd( 1):
echo "{{.loopindex1}} -> {{.loopitem}}"
-
4 -> beautiful world
-
.. ok
. ok
Logs with different verbose level
Raw logs with different verbose level