Scripts in bin: improved -help message for foamEtcFile

This commit is contained in:
Chris Greenshields
2017-05-29 23:05:38 +01:00
parent 2d0ccb4f8e
commit 87eeba42c4

View File

@ -44,14 +44,9 @@
# #
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
usage() { usage() {
[ "${optQuiet:-$optSilent}" = true ] && exit 1
exec 1>&2
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
cat<<USAGE cat<<USAGE
Usage: ${0##*/} [OPTION] fileName Usage: ${0##*/} [OPTION] fileName
${0##*/} [OPTION] -list
options: options:
-all return all files (otherwise stop after the first match) -all return all files (otherwise stop after the first match)
-list list the directories to be searched -list list the directories to be searched
@ -63,18 +58,30 @@ options:
in the form Maj.Min.Rev (eg, 1.7.0) in the form Maj.Min.Rev (eg, 1.7.0)
-help print the usage -help print the usage
Locate user/group/shipped file with semantics similar to the Searches for OpenFOAM configuration files, that are generally found in the
~OpenFOAM/fileName expansion. installation "etc" directory, but can be located in the following locations,
listed in order of precedence:
- user level: \${HOME}/.OpenFOAM
- group level: \$FOAM_INST_DIR/site
- other level: \$WM_PROJECT_DIR/etc
The options can also be specified as a single character The options can also be specified as a single character
(eg, '-q' instead of '-quiet'), but must not be grouped. (eg, '-q' instead of '-quiet'), but must not be grouped.
Exit status Exit status
0 when the file is found. Print resolved path to stdout. 0 when the file is found. Print resolved path to stdout.
1 for miscellaneous errors. 1 for miscellaneous errors.
2 when the file is not found. 2 when the file is not found.
USAGE USAGE
}
error() {
[ "${optQuiet:-$optSilent}" = true ] && exit 1
exec 1>&2
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
usage
exit 1 exit 1
} }
@ -137,7 +144,7 @@ while [ "$#" -gt 0 ]
do do
case "$1" in case "$1" in
-h | -help) -h | -help)
usage usage && exit 0
;; ;;
-a | -all) -a | -all)
optAll=true optAll=true
@ -146,7 +153,7 @@ do
optList=true optList=true
;; ;;
-m | -mode) -m | -mode)
[ "$#" -ge 2 ] || usage "'$1' option requires an argument" [ "$#" -ge 2 ] || error "'$1' option requires an argument"
mode="$2" mode="$2"
# sanity check: # sanity check:
@ -154,13 +161,13 @@ do
*u* | *g* | *o* ) *u* | *g* | *o* )
;; ;;
*) *)
usage "'$1' option with invalid mode '$mode'" error "'$1' option with invalid mode '$mode'"
;; ;;
esac esac
shift shift
;; ;;
-p | -prefix) -p | -prefix)
[ "$#" -ge 2 ] || usage "'$1' option requires an argument" [ "$#" -ge 2 ] || error "'$1' option requires an argument"
prefixDir="$2" prefixDir="$2"
shift shift
;; ;;
@ -171,7 +178,7 @@ do
optSilent=true optSilent=true
;; ;;
-v | -version) -v | -version)
[ "$#" -ge 2 ] || usage "'$1' option requires an argument" [ "$#" -ge 2 ] || error "'$1' option requires an argument"
version="$2" version="$2"
# convert x.y.z -> xyz version (if installation looked like debian) # convert x.y.z -> xyz version (if installation looked like debian)
if [ -n "$versionNum" ] if [ -n "$versionNum" ]
@ -185,7 +192,7 @@ do
break break
;; ;;
-*) -*)
usage "unknown option: '$*'" error "unknown option: '$*'"
;; ;;
*) *)
break break
@ -248,7 +255,7 @@ if [ "$optList" = true ]
then then
# list directories, or potential file locations # list directories, or potential file locations
[ "$nArgs" -le 1 ] || usage [ "$nArgs" -le 1 ] || error
# a silly combination, but -quiet does have precedence # a silly combination, but -quiet does have precedence
[ "$optQuiet" = true ] && exit 0 [ "$optQuiet" = true ] && exit 0
@ -265,7 +272,7 @@ then
else else
[ "$nArgs" -eq 1 ] || usage [ "$nArgs" -eq 1 ] || error
# general error, eg file not found # general error, eg file not found
exitCode=2 exitCode=2