From 0b1c761075f50ff273c0470b241f62f341de489c Mon Sep 17 00:00:00 2001 From: mark Date: Thu, 16 Jun 2016 19:50:38 +0200 Subject: [PATCH] STYLE: provide 'die' as alternative to 'usage' - make option parsing more consistent --- etc/relocateQt | 5 ++- etc/tools/ThirdPartyFunctions | 11 +++++++ makeCCMIO | 12 +++----- makeCGAL | 14 ++------- makeCmake | 5 ++- makeGcc | 17 +++-------- makeGperftools | 4 +-- makeLLVM | 10 ++---- makeParaView | 57 ++++++++++++----------------------- makeParaView3 | 51 +++++++++++-------------------- makeQt | 5 ++- 11 files changed, 69 insertions(+), 122 deletions(-) diff --git a/etc/relocateQt b/etc/relocateQt index ac6f186..1542115 100755 --- a/etc/relocateQt +++ b/etc/relocateQt @@ -69,17 +69,16 @@ do ;; -f | -force) forceOpt=true - shift ;; [1-9]* | qt-[1-9]*) qtVERSION="${1%%/}"; qtVERSION="${qtVERSION#qt-}" - shift ;; *) - usage "unknown option/argument: '$*'" + die "unknown option/argument: '$1'" ;; esac + shift done #------------------------------------------------------------------------------ diff --git a/etc/tools/ThirdPartyFunctions b/etc/tools/ThirdPartyFunctions index 2e27969..9cf85c1 100644 --- a/etc/tools/ThirdPartyFunctions +++ b/etc/tools/ThirdPartyFunctions @@ -61,6 +61,17 @@ then fi +# Report error and exit +die() +{ + exec 1>&2 + echo + echo "Error: see '${0##*/} -help' for usage" + while [ "$#" -ge 1 ]; do echo " $1"; shift; done + echo + exit 1 +} + # Test if it matches "*-none" _foamIsNone() { diff --git a/makeCCMIO b/makeCCMIO index 8990572..022cb68 100755 --- a/makeCCMIO +++ b/makeCCMIO @@ -90,23 +90,19 @@ do ;; lib|libso) targetType="$1" - shift ;; libccmio-[1-9]*) ccmioPACKAGE="${1%%/}" - shift ;; *) - usage "unknown option/argument: '$*'" + die "unknown option/argument: '$1'" ;; esac + shift done -# warn if unavailable -if [ ! -d ${ccmioPACKAGE} ] -then - usage "missing source directory '$ccmioPACKAGE'" -fi +# assert: directory must be available +[ -d "${ccmioPACKAGE}" ] || die "missing source directory '$ccmioPACKAGE'" #------------------------------------------------------------------------------ diff --git a/makeCGAL b/makeCGAL index 32aa5f8..4877165 100755 --- a/makeCGAL +++ b/makeCGAL @@ -106,40 +106,32 @@ do ;; -gcc) export CXX=g++ # use g++ - shift ;; -sys*) gmpPACKAGE="gmp-system" mpfrPACKAGE="mpfr-system" boostPACKAGE="boost-system" - shift ;; gmp-[4-9]* | gmp-system) gmpPACKAGE="${1%%/}" - shift ;; mpfr-[2-9]* | mpfr-system) mpfrPACKAGE="${1%%/}" - shift ;; CGAL-[0-9]*) cgalPACKAGE="${1%%/}" - shift ;; boost-[0-9]* | boost_[0-9]* | boost-system ) boostPACKAGE="${1%%/}" - shift ;; *) - usage "unknown option/argument: '$*'" + die "unknown option/argument: '$1'" ;; esac + shift done -if [ -z "$cgalPACKAGE" ] -then - usage "The cgal-VERSION was not specified" -fi +[ -n "$cgalPACKAGE" ] || die "The cgal-VERSION was not specified" #------------------------------------------------------------------------------ # diff --git a/makeCmake b/makeCmake index b3ca91d..a32cd1e 100755 --- a/makeCmake +++ b/makeCmake @@ -74,16 +74,15 @@ do -gcc) export CC=gcc # use gcc export CXX=g++ # use g++ - shift ;; cmake-[1-9]*) cmakePACKAGE="${1%%/}" - shift ;; *) - usage "unknown option/argument: '$*'" + die "unknown option/argument: '$1'" ;; esac + shift done diff --git a/makeGcc b/makeGcc index 70721c4..2552b2d 100755 --- a/makeGcc +++ b/makeGcc @@ -91,41 +91,32 @@ do ;; -no-multi*) GCC_BUILD_OPTIONS="--disable-multilib" - shift ;; -sys*) gmpPACKAGE="gmp-system" mpfrPACKAGE="mpfr-system" mpcPACKAGE="mpc-system" - shift ;; gmp-[4-9]* | gmp-system) gmpPACKAGE="${1%%/}" - shift ;; mpfr-[2-9]* | mpfr-system) mpfrPACKAGE="${1%%/}" - shift ;; mpc-[0-9]* | mpc-system) mpcPACKAGE="${1%%/}" - shift ;; gcc-[4-9]*) gccPACKAGE="${1%%/}" - shift ;; *) - usage "unknown option/argument: '$*'" + die "unknown option/argument: '$1'" ;; esac + shift done -if [ -z "$gccPACKAGE" ] -then - usage "Please specify gcc-VERSION" - exit 1 -fi +[ -n "$gccPACKAGE" ] || die "The gcc-VERSION was not specified" cat<&2 while [ "$#" -ge 1 ]; do echo "$1"; shift; done cat<&2 while [ "$#" -ge 1 ]; do echo "$1"; shift; done cat<