diff options
author | Richard Maw <richard.maw@codethink.co.uk> | 2021-08-06 13:33:24 +0100 |
---|---|---|
committer | Richard Maw <richard.maw@codethink.co.uk> | 2021-08-06 16:31:18 +0100 |
commit | eeb4289de025dfeb639cdd21136763e3af4b7dfb (patch) | |
tree | ce1d0e6ae2e1b5f138213d9544b8a9d8f06c7ecf | |
parent | 99a757068207bb9c745dd913a30ba5a560ceb998 (diff) | |
download | subplot-eeb4289de025dfeb639cdd21136763e3af4b7dfb.tar.gz |
bash template: Provide captures to cleanups
-rw-r--r-- | share/bash/template/template.sh.tera | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/share/bash/template/template.sh.tera b/share/bash/template/template.sh.tera index 6ee88f5..67134f3 100644 --- a/share/bash/template/template.sh.tera +++ b/share/bash/template/template.sh.tera @@ -88,9 +88,11 @@ files_set "$filename" "$contents" ###################################### # Scenario: {{ scenario.title }} scenario_{{ loop.index }}() { - local title scendir step name text ret cleanups steps + local title scendir step name text ret declare -a cleanups declare -a steps + declare -a cleanups_captures + declare -A captures title="$(decode_base64 '{{ scenario.title | base64 }}')" echo "scenario: $title" @@ -103,6 +105,7 @@ scenario_{{ loop.index }}() { ctx_new cleanups[0]='' steps[0]='' + cleanups_captures[0]='' ret=0 {% for step in scenario.steps %} @@ -113,9 +116,11 @@ scenario_{{ loop.index }}() { echo " step: $step" cap_new + captures=() {% for part in step.parts %}{% if part.CapturedText is defined -%} name="$(decode_base64 '{{ part.CapturedText.name | base64 }}')" text="$(decode_base64 '{{ part.CapturedText.text | base64 }}')" + captures["$name"]="$text" cap_set "$name" "$text" {% endif -%} {% endfor -%} @@ -125,9 +130,9 @@ scenario_{{ loop.index }}() { if [ "$cleanup" != "" ] then {% raw %} - i=${#cleanups} - cleanups[$i]="$cleanup" - steps[$i]="$step" + cleanups+=("$cleanup") + steps+=("$step") + cleanups_captures+=("${captures[*]@A}") {% endraw %} fi else @@ -141,6 +146,13 @@ scenario_{{ loop.index }}() { do step="${steps[$i]}" func="${cleanups[$i]}" + eval "${cleanups_captures[$i]}" + cap_new + for name in "${!captures[@]}" + do + text="${captures["$name"]}" + cap_set "$name" "$text" + done echo " cleanup: $step" $func done |