arguments: fix unreachable and poor argument error handling
all scripts use `set -e` which means that if getop fails, the subsequent error check that would print an error in addition to any printed by getopt itself would never actually be reached. the first though here would be to remove the pointless error check, but getopt does not include the word "error" with an unrecognised option failure, nor does it use colour to highlight problems, both of which mean that it is a little lacking in terms of highlighting problems to users. thus we properly capture and use the exit code here and output an appropriate message per invalid argument vs getopt internal error. also, removed the redundant stderr redirection which is already done by Echo_error(). Gbp-Dch: Short
This commit is contained in:
parent
d6096622f9
commit
cf2a9b951c
|
@ -10,11 +10,14 @@
|
|||
|
||||
Arguments ()
|
||||
{
|
||||
ARGUMENTS="$(getopt --longoptions breakpoints,color,conffile:,debug,force,help,quiet,usage,verbose,version --name=${PROGRAM} --options c:huv --shell sh -- "${@}")"
|
||||
local ERR=0
|
||||
ARGUMENTS="$(getopt --longoptions breakpoints,color,conffile:,debug,force,help,quiet,usage,verbose,version --name=${PROGRAM} --options c:huv --shell sh -- "${@}")" || ERR=$?
|
||||
|
||||
if [ $? -ne 0 ]
|
||||
then
|
||||
Echo_error "terminating" >&2
|
||||
if [ $ERR -eq 1 ]; then
|
||||
Echo_error "invalid arguments"
|
||||
exit 1
|
||||
elif [ $ERR -ne 0 ]; then
|
||||
Echo_error "getop failure"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
|
|
@ -164,10 +164,15 @@ Local_arguments ()
|
|||
bootstrap-qemu-exclude:"
|
||||
# Remove spaces added by indentation
|
||||
LONG_OPTIONS="$(echo ${LONG_OPTIONS} | tr -d ' ')"
|
||||
ARGUMENTS="$(getopt --longoptions ${LONG_OPTIONS} --name="${PROGRAM}" --options a:d:m:k:b:s:c:huv --shell sh -- "${@}")"
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
Echo_error "terminating" >&2
|
||||
local ERR=0
|
||||
ARGUMENTS="$(getopt --longoptions ${LONG_OPTIONS} --name="${PROGRAM}" --options a:d:m:k:b:s:c:huv --shell sh -- "${@}")" || ERR=$?
|
||||
|
||||
if [ $ERR -eq 1 ]; then
|
||||
Echo_error "invalid arguments"
|
||||
exit 1
|
||||
elif [ $ERR -ne 0 ]; then
|
||||
Echo_error "getop failure"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
|
Loading…
Reference in New Issue