diff options
author | Anthony Wilson <wilsonan@us.ibm.com> | 2018-09-26 16:06:38 -0500 |
---|---|---|
committer | Anthony Wilson <wilsonan@us.ibm.com> | 2018-10-23 10:40:38 -0500 |
commit | ea87db4096ffd74de16847a3f86a86eb0f129b3c (patch) | |
tree | 39ea54e1819173dfb5d0b85a9d3ccc26c22fa67b | |
parent | 3ae0a3549adbd98ea0dbeedb2caa76ed8283472c (diff) | |
download | phosphor-state-manager-ea87db4096ffd74de16847a3f86a86eb0f129b3c.tar.gz phosphor-state-manager-ea87db4096ffd74de16847a3f86a86eb0f129b3c.zip |
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>
-rw-r--r-- | obmcutil | 26 |
1 files changed, 21 insertions, 5 deletions
@@ -42,6 +42,13 @@ state_query () 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 @@ handle_cmd () printf "%s = %s\n" $property $STATE done ;; + *) + print_usage_err "Invalid command '$1'" + ;; + esac +} + +for arg in "$@"; do + case $arg in -h|--help) print_help ;; + -*) + print_usage_err "Unknown option: $arg" + ;; *) - echo "ERROR: Invalid Choice: '$1'" - echo "$USAGE" + handle_cmd $arg + break ;; esac -} - -handle_cmd $1 +done |