Skip to content

Commit 47f5536

Browse files
committed
Added new vcr command "stdin"
This patch add a new "stdin" command that will type to the next command stdin prompt. The command must be the last one on the vcr command line. An usage example is "# vcr: stdin=Some text to use as stdin input". Signed-off-by: Rafael Guterres Jeffman <rjeffman@redhat.com>
1 parent b23c682 commit 47f5536

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

vcr

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,10 @@ template_script() {
6363
# vcr: -- sleep[=<time>]: wait <time>
6464
# vcr: -- prompt=/<regex>/: Set the "prompt" that marks end of command
6565
# vcr: -- timeout=<time>: Set time to wait for the next command to finish
66+
# vcr: -- stdin=<textline>: Type <textline> for the next command stdin
6667
# vcr: --
6768
# vcr: -- <time>: Can be 's' (seconds), 'm' (minutes) or 'ms' (miliseconds)
69+
# vcr: -- "stdin" must be the last command on the line
6870
# vcr: -- Multiple commands can be used like "# vcr: show clear sleep=500ms"
6971
EOF
7072
}
@@ -142,10 +144,7 @@ echo "Sleep ${PRECUT}"
142144

143145
# Initialize VCR vars
144146
PROMPT=" ${DEFAULT_PROMPT}"
145-
REM=""
146147
WAIT="${PROMPT}"
147-
SLEEP=""
148-
HIDE=""
149148

150149
# shellcheck disable=SC2312
151150
sed -e '/^#!/d' -e '/^$/d' < "${SCRIPT}" | while read -r line
@@ -189,6 +188,11 @@ do
189188
# shellcheck disable=SC2001
190189
WAIT="@$(sed -e 's#.*timeout=\([^ ]*\).*#\1#' <<< "${line}") ${PROMPT}"
191190
fi
191+
if [[ "${line}" =~ "stdin" ]]
192+
then
193+
# shellcheck disable=SC2001
194+
TEXTLINE="$(sed -e 's#.*stdin=\(.*\)#\1#' <<< "${line}")"
195+
fi
192196
continue
193197
fi
194198
# Run 'noop' commands for displaying comments
@@ -200,20 +204,27 @@ do
200204
fi
201205
# Run and wait for command
202206
grep -q "\"" <<< "${line}" && echo "Type '${REM}${line}${REM}'" || echo "Type \"${REM}${line}${REM}\""
203-
[[ -z "${HIDE}" ]] && echo -e "Sleep 500ms"
207+
[[ -z "${HIDE:-}" ]] && echo -e "Sleep 500ms"
204208
echo "Enter"
205-
if [[ -n "${REM}" ]]
209+
if [[ -n "${TEXTLINE:-}" ]]
210+
then
211+
echo "Type '${TEXTLINE}'"
212+
[[ -z "${HIDE:-}" ]] && echo -e "Sleep 500ms"
213+
echo "Enter"
214+
fi
215+
if [[ -n "${REM:-}" ]]
206216
then
207217
echo "Sleep ${SLEEP:-${COMMENT_SLEEP}}"
208218
else
209-
[[ -z "${SLEEP}" ]] && echo "Wait${WAIT}" || echo "Sleep ${SLEEP}"
219+
[[ -z "${SLEEP:-}" ]] && echo "Wait${WAIT}" || echo "Sleep ${SLEEP}"
210220
fi
211221

212222
# Reset VCR vars
213223
PROMPT=" ${DEFAULT_PROMPT}"
214-
REM=""
215224
WAIT="${PROMPT}"
225+
REM=""
216226
SLEEP=""
227+
TEXTLINE=""
217228
done
218229

219230
echo "Sleep ${POSTCUT}"

0 commit comments

Comments
 (0)