Add command line parser and --help option
authorAlexander Barton <alex@barton.de>
Mon, 1 Sep 2014 22:28:30 +0000 (00:28 +0200)
committerAlexander Barton <alex@barton.de>
Mon, 1 Sep 2014 22:28:30 +0000 (00:28 +0200)
scripts/trigger-rcmd

index 89f61f1b148d37a817106b3c0df3a50e9b371c6f..7db861fb8e370119ff18c91f1986a9f0a8dbd091 100755 (executable)
@@ -15,6 +15,11 @@ RCMD_D="/usr/local/etc/rcmd.d"
 
 PATH="$PATH:/usr/local/sbin:/usr/sbin"
 
+do_help() {
+       echo "Usage: $0 <rcmd> [<rcmd> [...]]" >&2
+       exit 2
+}
+
 do_rcmd() {
        SYSTEM="localhost"
        IFACE="eth0"
@@ -87,10 +92,17 @@ do_rcmd() {
        [ $r -eq 0 ] && return 0 || return 1
 }
 
-if [ $# -lt 1 ]; then
-       echo "Usage: $0 <rcmd> [<rcms> [...]]" >&2
-       exit 2
-fi
+while [ $# -gt 0 ]; do
+       case "$1" in
+         --help|-*)
+               do_help; ;;
+         *)
+               break
+       esac
+       shift
+done
+
+[ $# -gt 0 ] || do_help
 
 result=0
 while [ $# -gt 0 ]; do