From a20725518fead2694f62fa2a7ae5e08ece7915bf Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 15 Sep 2020 20:54:54 +0200 Subject: support multiple arguments --- htgen | 38 ++++++++++++++++++++++++++------------ 1 file 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 ## }}} -- cgit v1.2.3