feat(templates): adds arbitrary shell execution and pda-getting
This commit is contained in:
parent
2ca32769d5
commit
f9ff2c0d62
8 changed files with 139 additions and 11 deletions
2
testdata/template-enum-err.ct
vendored
2
testdata/template-enum-err.ct
vendored
|
|
@ -2,4 +2,4 @@
|
|||
$ fecho tpl {{ enum .LEVEL "info" "warn" }}
|
||||
$ pda set level@tple < tpl
|
||||
$ pda get level@tple LEVEL=debug --> FAIL
|
||||
FAIL cannot get 'level@tple': template: cmd:1:3: executing "cmd" at <enum .LEVEL "info" "warn">: error calling enum: invalid value 'debug', allowed: [info warn]
|
||||
FAIL cannot get 'level@tple': invalid value 'debug', allowed: [info warn]
|
||||
|
|
|
|||
5
testdata/template-pda-ref-err.ct
vendored
Normal file
5
testdata/template-pda-ref-err.ct
vendored
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
# pda errors on missing key
|
||||
$ fecho tpl1 {{ pda "missing" }}
|
||||
$ pda set ref@tplre < tpl1
|
||||
$ pda get ref@tplre --> FAIL
|
||||
FAIL cannot get 'ref@tplre': pda: cannot get 'missing': no such key
|
||||
13
testdata/template-pda-ref.ct
vendored
Normal file
13
testdata/template-pda-ref.ct
vendored
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
# pda function cross-references another key
|
||||
$ pda set base https://example.com
|
||||
$ fecho tpl1 {{ pda "base" }}/api
|
||||
$ pda set endpoint@tplr < tpl1
|
||||
$ pda get endpoint@tplr
|
||||
https://example.com/api
|
||||
# pda with substitution vars passed through
|
||||
$ fecho tpl2 Hello, {{ default "World" .NAME }}
|
||||
$ pda set greeting@tplr < tpl2
|
||||
$ fecho tpl3 {{ pda "greeting@tplr" }}!
|
||||
$ pda set shout@tplr < tpl3
|
||||
$ pda get shout@tplr NAME=Alice
|
||||
Hello, Alice!
|
||||
2
testdata/template-require-err.ct
vendored
2
testdata/template-require-err.ct
vendored
|
|
@ -2,4 +2,4 @@
|
|||
$ fecho tpl {{ require .FILE }}
|
||||
$ pda set tmpl@tplr < tpl
|
||||
$ pda get tmpl@tplr --> FAIL
|
||||
FAIL cannot get 'tmpl@tplr': template: cmd:1:3: executing "cmd" at <require .FILE>: error calling require: required value is missing or empty
|
||||
FAIL cannot get 'tmpl@tplr': required value is missing or empty
|
||||
|
|
|
|||
5
testdata/template-shell.ct
vendored
Normal file
5
testdata/template-shell.ct
vendored
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
# Shell function executes a command and returns stdout
|
||||
$ fecho tpl1 {{ shell "echo hello" }}
|
||||
$ pda set shelltest@tpls < tpl1
|
||||
$ pda get shelltest@tpls
|
||||
hello
|
||||
Loading…
Add table
Add a link
Reference in a new issue