summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2020-09-15 20:54:54 +0200
committertv <tv@krebsco.de>2020-09-15 20:54:54 +0200
commita20725518fead2694f62fa2a7ae5e08ece7915bf (patch)
tree42d611bcb74e9968a4eda90bbbf661ba78714cdb
parent67616cb9f0fe6c0bb23afc2f9bfc1b9d43bed58f (diff)
support multiple arguments
-rwxr-xr-xhtgen38
1 files changed, 26 insertions, 12 deletions
diff --git a/htgen b/htgen
index 78696be..ba6976b 100755
--- a/htgen
+++ b/htgen
@@ -4,18 +4,32 @@ set -euf
Server=htgen
-## htgen --serve {{{
-case $# in
- (1)
- case "$1" in
- (--serve)
- HTGEN_HOST=${HTGEN_HOST-0.0.0.0}
- HTGEN_PORT=${HTGEN_PORT-42380}
- HTGEN_SCRIPT=${HTGEN_SCRIPT-:}
- TCPSERVER_OPTS='-c 423 -t 2 -D'
- echo "#### $Server $HTGEN_HOST:$HTGEN_PORT" >&2
- exec tcpserver $TCPSERVER_OPTS "$HTGEN_HOST" "$HTGEN_PORT" "$0"
- esac
+## parse arguments {{{
+action=handle_request
+while test $# -gt 0; do
+ case $1 in)
+ --serve) action=serve; shift; continue;;
+ *) echo "$0: error: bad argument: $1" >&2; exit 1;;
+ esac
+done
+## }}}
+## dispatch on $action {{
+case $action in
+ handle_request)
+ : # fall through for handling the request
+ ;;
+ serve)
+ HTGEN_HOST=${HTGEN_HOST-0.0.0.0}
+ HTGEN_PORT=${HTGEN_PORT-42380}
+ HTGEN_SCRIPT=${HTGEN_SCRIPT-:}
+ TCPSERVER_OPTS='-c 423 -t 2 -D'
+ echo "#### $Server $HTGEN_HOST:$HTGEN_PORT" >&2
+ exec tcpserver $TCPSERVER_OPTS "$HTGEN_HOST" "$HTGEN_PORT" "$0"
+ ;;
+ *)
+ echo "$0: error: bad action: $action" >&2
+ exit 2
+ ;;
esac
## }}}