Refactor common code into a function

This commit is contained in:
Debarshi Ray 2018-10-15 17:05:49 +02:00
parent a0a9e7dc03
commit f3eab6afca

View file

@ -174,6 +174,14 @@ exit_if_extra_operand()
}
exit_if_unrecognized_option()
{
echo "$0: unrecognized option '$1'"
echo "Try '$0 --help' for more information."
exit 1
}
usage()
{
echo "Usage: $0 [-v | --verbose] create [--candidate-registry]"
@ -197,9 +205,7 @@ while [[ "$1" == -* ]]; do
exec 42>&2
;;
* )
echo "$0: unrecognized option '$1'"
echo "Try '$0 --help' for more information."
exit 1
exit_if_unrecognized_option $1
esac
shift
done
@ -221,9 +227,7 @@ case $op in
registry=$registry_candidate
;;
* )
echo "$0: unrecognized option '$1'"
echo "Try '$0 --help' for more information."
exit 1
exit_if_unrecognized_option $1
esac
shift
done
@ -235,9 +239,7 @@ case $op in
while [[ "$1" == -* ]]; do
case $1 in
* )
echo "$0: unrecognized option '$1'"
echo "Try '$0 --help' for more information."
exit 1
exit_if_unrecognized_option $1
esac
shift
done