From 87eeba42c48ab615a618cb064d53408b5fd9d486 Mon Sep 17 00:00:00 2001 From: Chris Greenshields Date: Mon, 29 May 2017 23:05:38 +0100 Subject: [PATCH] Scripts in bin: improved -help message for foamEtcFile --- bin/foamEtcFile | 49 ++++++++++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/bin/foamEtcFile b/bin/foamEtcFile index e2d27ac81..5e984117f 100755 --- a/bin/foamEtcFile +++ b/bin/foamEtcFile @@ -44,14 +44,9 @@ # #------------------------------------------------------------------------------- usage() { - [ "${optQuiet:-$optSilent}" = true ] && exit 1 - - exec 1>&2 - while [ "$#" -ge 1 ]; do echo "$1"; shift; done cat<&2 + while [ "$#" -ge 1 ]; do echo "$1"; shift; done + usage exit 1 } @@ -137,7 +144,7 @@ while [ "$#" -gt 0 ] do case "$1" in -h | -help) - usage + usage && exit 0 ;; -a | -all) optAll=true @@ -146,7 +153,7 @@ do optList=true ;; -m | -mode) - [ "$#" -ge 2 ] || usage "'$1' option requires an argument" + [ "$#" -ge 2 ] || error "'$1' option requires an argument" mode="$2" # sanity check: @@ -154,13 +161,13 @@ do *u* | *g* | *o* ) ;; *) - usage "'$1' option with invalid mode '$mode'" + error "'$1' option with invalid mode '$mode'" ;; esac shift ;; -p | -prefix) - [ "$#" -ge 2 ] || usage "'$1' option requires an argument" + [ "$#" -ge 2 ] || error "'$1' option requires an argument" prefixDir="$2" shift ;; @@ -171,7 +178,7 @@ do optSilent=true ;; -v | -version) - [ "$#" -ge 2 ] || usage "'$1' option requires an argument" + [ "$#" -ge 2 ] || error "'$1' option requires an argument" version="$2" # convert x.y.z -> xyz version (if installation looked like debian) if [ -n "$versionNum" ] @@ -185,7 +192,7 @@ do break ;; -*) - usage "unknown option: '$*'" + error "unknown option: '$*'" ;; *) break @@ -248,7 +255,7 @@ if [ "$optList" = true ] then # list directories, or potential file locations - [ "$nArgs" -le 1 ] || usage + [ "$nArgs" -le 1 ] || error # a silly combination, but -quiet does have precedence [ "$optQuiet" = true ] && exit 0 @@ -265,7 +272,7 @@ then else - [ "$nArgs" -eq 1 ] || usage + [ "$nArgs" -eq 1 ] || error # general error, eg file not found exitCode=2