@@ -4,7 +4,7 @@ trap cleanup SIGINT SIGTERM EXIT
4
4
5
5
SCRIPTPATH=" $( cd -- " $( dirname " $0 " ) " > /dev/null 2>&1 ; pwd -P ) "
6
6
7
- function check_prereq() {
7
+ check_prereq () {
8
8
prog=$1
9
9
if ! command -v ${prog} & > /dev/null
10
10
then
@@ -13,45 +13,79 @@ function check_prereq() {
13
13
fi
14
14
}
15
15
16
- function cleanup() {
17
- if [ -d $WKDIR ]
18
- then
16
+ cleanup () {
17
+ if [[ -n " ${WKDIR-} " && -d $WKDIR ]]; then
19
18
rm -rf $WKDIR
20
19
fi
21
20
}
22
21
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"
27
39
exit 1
28
40
}
29
41
30
42
set +u
31
- while getopts ' h ' flag; do
43
+ while getopts ' :hn:u ' flag; do
32
44
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
+ ;;
34
62
esac
35
- shift
36
63
done
64
+ shift $(( OPTIND - 1 ))
37
65
set -u
38
66
67
+ DEMO_SCRIPT=" ${1-} "
68
+
69
+ if [ -z $DEMO_SCRIPT ]; then
70
+ usage
71
+ fi
72
+
39
73
WKDIR=$( mktemp -d -t generate-asciidemo.XXXXX)
40
- if [ ! -d ${WKDIR} ]
41
- then
74
+ if [ ! -d ${WKDIR} ]; then
42
75
echo " unable to create temporary workspace"
43
76
exit 2
44
77
fi
45
78
46
- for prereq in " asciinema curl"
47
- do
79
+ for prereq in " asciinema curl" ; do
48
80
check_prereq ${prereq}
49
81
done
50
82
51
83
52
84
curl https://raw.githubusercontent.com/zechris/asciinema-rec_script/main/bin/asciinema-rec_script -o ${WKDIR} /asciinema-rec_script
53
85
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}
55
87
56
- asciinema upload ${WKDIR} /catalogd-demo.cast
88
+ if [ -n " ${UPLOAD-} " ]; then
89
+ asciinema upload ${WKDIR} /${DEMO_NAME} .cast
90
+ fi
57
91
0 commit comments