Improved sztest argument parsing.
authorFredrik Tolf <fredrik@dolda2000.com>
Thu, 24 Feb 2011 09:36:56 +0000 (10:36 +0100)
committerFredrik Tolf <fredrik@dolda2000.com>
Thu, 24 Feb 2011 09:36:56 +0000 (10:36 +0100)
sztest

diff --git a/sztest b/sztest
index 2393971..ca7182c 100755 (executable)
--- a/sztest
+++ b/sztest
@@ -1,9 +1,8 @@
 #!/bin/sh
 
-if [ $# -lt 1 ]; then
-    echo "usage: sztest [-H SYS-HEADER] [-L LOCAL-HEADER] TYPE [CCFLAGS...]" >&2
-    exit 1
-fi
+usage() {
+    echo "usage: sztest [-h] [-H SYS-HEADER] [-L LOCAL-HEADER] TYPE [CCFLAGS...]"
+}
 
 sheaders=
 lheaders=
@@ -11,6 +10,10 @@ while [ "${1:0:1}" = "-" ]; do
     opt="$1"
     shift
     case "$opt" in
+       "-h")
+           usage
+           exit 0
+           ;;
        "-H")
            sheaders="$sheaders $1"
            shift
@@ -21,6 +24,10 @@ while [ "${1:0:1}" = "-" ]; do
            ;;
     esac
 done
+if [ $# -lt 1 ]; then
+    usage >&2
+    exit 1
+fi
 type="$1"
 shift
 file="$(mktemp /tmp/sztestXXXXXX)"