From eeb4289de025dfeb639cdd21136763e3af4b7dfb Mon Sep 17 00:00:00 2001 From: Richard Maw Date: Fri, 6 Aug 2021 13:33:24 +0100 Subject: bash template: Provide captures to cleanups --- share/bash/template/template.sh.tera | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'share') 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 -- cgit v1.2.1