obmcutil: Update argument handling
In anticipation of new options being added to the program,
this change should make it easier and cleaner to integrate
those options.
Change-Id: Ie996c34ef9c8493d68bc17d6e7a6d39a537ba2cd
Signed-off-by: Anthony Wilson <wilsonan@us.ibm.com>
diff --git a/obmcutil b/obmcutil
index 61c85dd..26fd760 100644
--- a/obmcutil
+++ b/obmcutil
@@ -42,6 +42,13 @@
printf "%-20s: %s\n" $4 $state
}
+print_usage_err ()
+{
+ echo "ERROR: $1" >&2
+ echo "$USAGE"
+ exit 1
+}
+
handle_cmd ()
{
case "$1" in
@@ -126,14 +133,23 @@
printf "%s = %s\n" $property $STATE
done
;;
- -h|--help)
- print_help
- ;;
*)
- echo "ERROR: Invalid Choice: '$1'"
- echo "$USAGE"
+ print_usage_err "Invalid command '$1'"
;;
esac
}
-handle_cmd $1
+for arg in "$@"; do
+ case $arg in
+ -h|--help)
+ print_help
+ ;;
+ -*)
+ print_usage_err "Unknown option: $arg"
+ ;;
+ *)
+ handle_cmd $arg
+ break
+ ;;
+ esac
+done