Skip to content

Commit becde51

Browse files
perdasilvaPer G. da Silva
and
Per G. da Silva
authored
Make generate-asciidemo.sh generic (operator-framework#1755)
Signed-off-by: Per G. da Silva <[email protected]> Co-authored-by: Per G. da Silva <[email protected]>
1 parent f8fac24 commit becde51

File tree

4 files changed

+52
-76
lines changed

4 files changed

+52
-76
lines changed

Diff for: Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,6 @@ deploy-docs: venv
420420
# The demo script requires to install asciinema with: brew install asciinema to run on mac os envs.
421421
.PHONY: demo-update #EXHELP build demo
422422
demo-update:
423-
./hack/demo/generate-asciidemo.sh
423+
./hack/demo/generate-asciidemo.sh -u -n catalogd-demo catalogd-demo-script.sh
424424

425425
include Makefile.venv

Diff for: hack/demo/demo-script.sh renamed to hack/demo/catalogd-demo-script.sh

-1
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,3 @@ curl -k https://localhost:8081/catalogs/operatorhubio/api/v1/all | jq -s '.[] |
3636
curl -k https://localhost:8081/catalogs/operatorhubio/api/v1/all | jq -s '.[] | select(.schema == "olm.channel") | select(.package == "wavefront") | .name'
3737
# check what bundles are included in the wavefront package
3838
curl -k https://localhost:8081/catalogs/operatorhubio/api/v1/all | jq -s '.[] | select(.schema == "olm.bundle") | select(.package == "wavefront") | .name'
39-

Diff for: hack/demo/generate-asciidemo.sh

+51-17
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ trap cleanup SIGINT SIGTERM EXIT
44

55
SCRIPTPATH="$( cd -- "$(dirname "$0")" > /dev/null 2>&1 ; pwd -P )"
66

7-
function check_prereq() {
7+
check_prereq() {
88
prog=$1
99
if ! command -v ${prog} &> /dev/null
1010
then
@@ -13,45 +13,79 @@ function check_prereq() {
1313
fi
1414
}
1515

16-
function cleanup() {
17-
if [ -d $WKDIR ]
18-
then
16+
cleanup() {
17+
if [[ -n "${WKDIR-}" && -d $WKDIR ]]; then
1918
rm -rf $WKDIR
2019
fi
2120
}
2221

23-
function usage() {
24-
echo "$0 [options]"
25-
echo "where options is"
26-
echo " h help (this message)"
22+
usage() {
23+
echo "$0 [options] <demo-script>"
24+
echo ""
25+
echo "options:"
26+
echo " -n <name>"
27+
echo " -u upload cast (default: false)"
28+
echo " -h help (this message)"
29+
echo ""
30+
echo "examples:"
31+
echo " # Generate asciinema demo described by gzip-demo-script.sh into gzip-demo-script.cast"
32+
echo " $0 gzip-demo-script.sh"
33+
echo ""
34+
echo " # Generate asciinema demo described by demo-script.sh into catalogd-demo.cast"
35+
echo " $0 -n catalogd-demo demo-script.sh"
36+
echo ""
37+
echo " # Generate and upload catalogd-demo.cast"
38+
echo " $0 -u -n catalogd-demo demo-script.sh"
2739
exit 1
2840
}
2941

3042
set +u
31-
while getopts 'h' flag; do
43+
while getopts ':hn:u' flag; do
3244
case "${flag}" in
33-
h) usage ;;
45+
h)
46+
usage
47+
;;
48+
n)
49+
DEMO_NAME="${OPTARG}"
50+
;;
51+
u)
52+
UPLOAD=true
53+
;;
54+
:)
55+
echo "Error: Option -${OPTARG} requires an argument."
56+
usage
57+
;;
58+
\?)
59+
echo "Error: Invalid option -${OPTARG}"
60+
usage
61+
;;
3462
esac
35-
shift
3663
done
64+
shift $((OPTIND - 1))
3765
set -u
3866

67+
DEMO_SCRIPT="${1-}"
68+
69+
if [ -z $DEMO_SCRIPT ]; then
70+
usage
71+
fi
72+
3973
WKDIR=$(mktemp -d -t generate-asciidemo.XXXXX)
40-
if [ ! -d ${WKDIR} ]
41-
then
74+
if [ ! -d ${WKDIR} ]; then
4275
echo "unable to create temporary workspace"
4376
exit 2
4477
fi
4578

46-
for prereq in "asciinema curl"
47-
do
79+
for prereq in "asciinema curl"; do
4880
check_prereq ${prereq}
4981
done
5082

5183

5284
curl https://raw.githubusercontent.com/zechris/asciinema-rec_script/main/bin/asciinema-rec_script -o ${WKDIR}/asciinema-rec_script
5385
chmod +x ${WKDIR}/asciinema-rec_script
54-
screencast=${WKDIR}/catalogd-demo.cast ${WKDIR}/asciinema-rec_script ${SCRIPTPATH}/demo-script.sh
86+
screencast=${WKDIR}/${DEMO_NAME}.cast ${WKDIR}/asciinema-rec_script ${SCRIPTPATH}/${DEMO_SCRIPT}
5587

56-
asciinema upload ${WKDIR}/catalogd-demo.cast
88+
if [ -n "${UPLOAD-}" ]; then
89+
asciinema upload ${WKDIR}/${DEMO_NAME}.cast
90+
fi
5791

Diff for: hack/demo/generate-gzip-asciidemo.sh

-57
This file was deleted.

0 commit comments

Comments
 (0)