From 7f24736ebc050a9b81d4d2db0158111486b1836b Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 20 May 2017 03:44:23 +0300 Subject: [PATCH] pvscheck: Handle invalid option error gracefully --- scripts/pvscheck.sh | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/scripts/pvscheck.sh b/scripts/pvscheck.sh index 79ed08f458..949021a174 100755 --- a/scripts/pvscheck.sh +++ b/scripts/pvscheck.sh @@ -50,7 +50,17 @@ help() { } getopts_error() { - printf '%s\n' "$1" >&2 + local msg="$1" ; shift + local do_help= + if test "$msg" = "--help" ; then + msg="$1" ; shift + do_help=1 + fi + printf '%s\n' "$msg" >&2 + if test -n "$do_help" ; then + printf '\n' >&2 + help >&2 + fi echo 'return 1' return 1 } @@ -146,8 +156,8 @@ getopts_long() { if test -n "$opt_base" ; then eval "local occurred_$opt_base=1" - eval "local act_1=\"\$act_1_$opt_base\"" - eval "local varname=\"\$varname_$opt_base\"" + eval "local act_1=\"\${act_1_$opt_base:-}\"" + eval "local varname=\"\${varname_$opt_base:-}\"" local need_val= local func= case "$act_1" in @@ -170,6 +180,9 @@ getopts_long() { eval "varname=\"\${act_3_${opt_base}:-$varname}\"" need_val=1 ;; + ("") + getopts_error --help "Wrong argument: $argument" + ;; esac if test -n "$need_val" ; then local val=