From 5947f9a337b868d728ffcd599fcb0f82aed180be Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Fri, 24 Nov 2017 10:27:11 +0100 Subject: [PATCH] ENH: more succinct output from command-line errors. - unknown options or missing option values now emit a shorter message without the entire usage. This makes it easier to identify the errors and is better aligned with the behaviour of GNU system tools. ==== $ simpleFoam -case Using: OpenFOAM-plus (see www.OpenFOAM.com) Build: plus-01234 Error: option '-case' requires an argument See 'simpleFoam -help' for usage ==== - provide for reduced (-help) and full (-help-full) usage information. In many cases the reduced usage provided sufficient and easier to find the information. - make -srcDoc an alias for -doc-source - no warnings about option aliases for future dates. --- bin/findEmptyMake | 2 +- bin/foamCheckJobs | 6 +- bin/foamCleanPath | 2 +- bin/foamCleanPolyMesh | 2 +- bin/foamCloneCase | 2 +- bin/foamCopySettings | 2 +- bin/foamCreateVideo | 2 +- bin/foamEndJob | 2 +- bin/foamEtcFile | 2 +- bin/foamExec | 2 +- bin/foamJob | 2 +- bin/foamLog | 2 +- bin/foamMonitor | 2 +- bin/foamNewApp | 2 +- bin/foamNewBC | 2 +- bin/foamNewCase | 2 +- bin/foamNewFunctionObject | 2 +- bin/foamPack | 2 +- bin/foamPackBin | 2 +- bin/foamPackDoxygen | 2 +- bin/foamPackThirdParty | 2 +- bin/foamPrintJobs | 9 +- bin/foamSearch | 2 +- bin/foamSequenceVTKFiles | 2 +- bin/foamUpdateCaseFileHeader | 2 +- bin/mpirunDebug | 2 +- bin/paraFoam | 2 +- bin/rmcore | 13 +-- bin/rm~all | 13 +-- bin/tools/foamConfigurePaths | 2 +- bin/tools/foamCreateCompletionCache | 2 +- bin/tools/foamCreateModuleInclude | 2 +- bin/tools/foamGrepExeTargets | 2 +- doc/Doxygen/Allwmake | 2 +- etc/codeTemplates/foamScript | 44 +++++++ etc/codeTemplates/source/foamNewSource | 2 +- etc/codeTemplates/template/foamNewTemplate | 2 +- etc/config.sh/bash_completion | 12 +- src/OpenFOAM/global/argList/argList.C | 130 +++++++++++++++------ src/OpenFOAM/global/argList/argList.H | 2 +- wmake/scripts/AllwmakeParseArguments | 2 +- wmake/scripts/wcleanBuild | 2 +- wmake/wclean | 2 +- wmake/wcleanLnIncludeAll | 5 +- wmake/wdep | 2 +- wmake/wmake | 2 +- wmake/wmakeCheckPwd | 2 +- wmake/wmakeCollect | 2 +- wmake/wmakeFilesAndOptions | 2 +- wmake/wmakeLnInclude | 2 +- wmake/wmakeLnIncludeAll | 2 +- wmake/wmakePrintBuild | 2 +- wmake/wrmdep | 2 +- wmake/wrmo | 2 +- 54 files changed, 207 insertions(+), 117 deletions(-) diff --git a/bin/findEmptyMake b/bin/findEmptyMake index e0ac838ca8..7ddbaaf178 100755 --- a/bin/findEmptyMake +++ b/bin/findEmptyMake @@ -48,7 +48,7 @@ USAGE while [ "$#" -gt 0 ] do case "$1" in - -h | -help) + -h | -help*) usage ;; -*) diff --git a/bin/foamCheckJobs b/bin/foamCheckJobs index e4142df73b..b6017e9c47 100755 --- a/bin/foamCheckJobs +++ b/bin/foamCheckJobs @@ -180,12 +180,10 @@ releaseLock () { # #------------------------------------------------------------------------------- +case "$1" in (-h | -help*) usage ;; esac + if [ $# -eq 1 ] then - if [ "$1" = "-h" -o "$1" = "-help" ] - then - usage - fi STATEFILE="$1" elif [ $# -eq 0 ] then diff --git a/bin/foamCleanPath b/bin/foamCleanPath index 70dd8c318b..1a812b0d1b 100755 --- a/bin/foamCleanPath +++ b/bin/foamCleanPath @@ -68,7 +68,7 @@ unset optDebug optStrip while [ "$#" -gt 0 ] do case "$1" in - -h | -help) + -h | -help*) usage ;; -debug) diff --git a/bin/foamCleanPolyMesh b/bin/foamCleanPolyMesh index e4f1eeec9e..befa5c8ea1 100755 --- a/bin/foamCleanPolyMesh +++ b/bin/foamCleanPolyMesh @@ -54,7 +54,7 @@ unset caseDir regionName while [ "$#" -gt 0 ] do case "$1" in - -h | -help) + -h | -help*) usage ;; -case) diff --git a/bin/foamCloneCase b/bin/foamCloneCase index d037cfa960..04df2f8a81 100755 --- a/bin/foamCloneCase +++ b/bin/foamCloneCase @@ -56,7 +56,7 @@ TIME_OPTION="head -1" while [ "$#" -gt 0 ] do case "$1" in - -h | -help) + -h | -help*) usage ;; -l | -latestTime) diff --git a/bin/foamCopySettings b/bin/foamCopySettings index 089dd2e08d..962edcdb62 100755 --- a/bin/foamCopySettings +++ b/bin/foamCopySettings @@ -63,7 +63,7 @@ USAGE while [ "$#" -gt 0 ] do case "$1" in - -h | -help) + -h | -help*) usage ;; -*) diff --git a/bin/foamCreateVideo b/bin/foamCreateVideo index d86f225763..3fe678c9e7 100755 --- a/bin/foamCreateVideo +++ b/bin/foamCreateVideo @@ -70,7 +70,7 @@ START_NUMBER='' while [ "$#" -gt 0 ] do case "$1" in - -h | -help) + -h | -help*) usage ;; -d | -directory) diff --git a/bin/foamEndJob b/bin/foamEndJob index 8273a04124..17c7a8fa5c 100755 --- a/bin/foamEndJob +++ b/bin/foamEndJob @@ -71,7 +71,7 @@ unset clearOpt stopOpt while [ "$#" -gt 0 ] do case "$1" in - -h | -help) + -h | -help*) usage ;; -case) diff --git a/bin/foamEtcFile b/bin/foamEtcFile index 58810ea21b..551050ec7c 100755 --- a/bin/foamEtcFile +++ b/bin/foamEtcFile @@ -196,7 +196,7 @@ unset optAll optList optShell optVersion while [ "$#" -gt 0 ] do case "$1" in - -h | -help) + -h | -help*) usage ;; -a | -all) diff --git a/bin/foamExec b/bin/foamExec index 38a032935c..cb6bd4496a 100755 --- a/bin/foamExec +++ b/bin/foamExec @@ -82,7 +82,7 @@ unset etcOpts while [ "$#" -gt 0 ] do case "$1" in - -h | -help) + -h | -help*) usage ;; -mode=*) diff --git a/bin/foamJob b/bin/foamJob index 7d0e0cf082..802122e9de 100755 --- a/bin/foamJob +++ b/bin/foamJob @@ -117,7 +117,7 @@ unset parallelOpt screenOpt waitOpt while [ "$#" -gt 0 ] do case "$1" in - -h | -help) + -h | -help*) usage ;; -case) diff --git a/bin/foamLog b/bin/foamLog index e784bf435c..021b935243 100755 --- a/bin/foamLog +++ b/bin/foamLog @@ -109,7 +109,7 @@ unset optList optQuiet localDB while [ "$#" -gt 0 ] do case "$1" in - -h | -help) + -h | -help*) printHelp exit 0 ;; diff --git a/bin/foamMonitor b/bin/foamMonitor index 8ae19858b0..e9f542aafb 100755 --- a/bin/foamMonitor +++ b/bin/foamMonitor @@ -87,7 +87,7 @@ GNUPLOT=$(which gnuplot) while [ "$#" -gt 0 ] do case "$1" in - -h | -help) + -h | -help*) usage ;; -i | -idle) diff --git a/bin/foamNewApp b/bin/foamNewApp index e960ea0b73..5d7898bfff 100755 --- a/bin/foamNewApp +++ b/bin/foamNewApp @@ -50,7 +50,7 @@ USAGE } case "$1" in -(-h | -help) +(-h | -help*) usage ;; -*) diff --git a/bin/foamNewBC b/bin/foamNewBC index ceac666502..caab8503ce 100755 --- a/bin/foamNewBC +++ b/bin/foamNewBC @@ -70,7 +70,7 @@ cap() { [ "$#" -gt 1 ] || usage case "$1" in -(-h | -help) +(-h | -help*) usage ;; (-f | -fixedValue | fixedValue) diff --git a/bin/foamNewCase b/bin/foamNewCase index 510152e91e..2b88170dd1 100755 --- a/bin/foamNewCase +++ b/bin/foamNewCase @@ -62,7 +62,7 @@ unset appName caseName listOpt while [ "$#" -gt 0 ] do case "$1" in - -h | -help) + -h | -help*) usage ;; -app) diff --git a/bin/foamNewFunctionObject b/bin/foamNewFunctionObject index 2445537572..c839576fb6 100755 --- a/bin/foamNewFunctionObject +++ b/bin/foamNewFunctionObject @@ -54,7 +54,7 @@ USAGE } case "$1" in -(-h | -help) +(-h | -help*) usage ;; -*) diff --git a/bin/foamPack b/bin/foamPack index 3e0a994e68..bd508b3ac8 100755 --- a/bin/foamPack +++ b/bin/foamPack @@ -52,7 +52,7 @@ unset outputDir nogit while [ "$#" -gt 0 ] do case "$1" in - -h | -help) + -h | -help*) usage ;; -nogit) diff --git a/bin/foamPackBin b/bin/foamPackBin index cdc548502f..ce16e10af3 100755 --- a/bin/foamPackBin +++ b/bin/foamPackBin @@ -81,7 +81,7 @@ packExt=tgz while [ "$#" -gt 0 ] do case "$1" in - -h | -help) + -h | -help*) usage ;; -b | -bzip2) diff --git a/bin/foamPackDoxygen b/bin/foamPackDoxygen index 4b34c8ecd8..a545bcee31 100755 --- a/bin/foamPackDoxygen +++ b/bin/foamPackDoxygen @@ -56,7 +56,7 @@ packExt=tgz while [ "$#" -gt 0 ] do case $1 in - -h | -help) + -h | -help*) usage ;; -b | -bzip2) diff --git a/bin/foamPackThirdParty b/bin/foamPackThirdParty index 7537872394..c52254d2bb 100755 --- a/bin/foamPackThirdParty +++ b/bin/foamPackThirdParty @@ -51,7 +51,7 @@ unset prefix outputDir nogit while [ "$#" -gt 0 ] do case "$1" in - -h | -help) + -h | -help*) usage ;; -nogit) diff --git a/bin/foamPrintJobs b/bin/foamPrintJobs index 58882edab9..abff48d616 100755 --- a/bin/foamPrintJobs +++ b/bin/foamPrintJobs @@ -105,14 +105,11 @@ leftStr() { # #------------------------------------------------------------------------------- +case "$1" in (-h | -help*) usage ;; esac + if [ $# -eq 1 ] then - if [ "$1" = "-h" -o "$1" = "-help" ] - then - usage - else - STATEFILE="$1" - fi + STATEFILE="$1" elif [ $# -eq 0 ] then STATEFILE=${STATEFILE:-$DEFSTATEFILE} diff --git a/bin/foamSearch b/bin/foamSearch index 504670d74a..854181c4a5 100755 --- a/bin/foamSearch +++ b/bin/foamSearch @@ -63,7 +63,7 @@ unset optCount while [ "$#" -gt 0 ] do case "$1" in - -h | -help) + -h | -help*) usage ;; -c | -count) diff --git a/bin/foamSequenceVTKFiles b/bin/foamSequenceVTKFiles index 8ebb755ace..8c6aa4e8e0 100755 --- a/bin/foamSequenceVTKFiles +++ b/bin/foamSequenceVTKFiles @@ -71,7 +71,7 @@ do DIR=$2 shift 2 ;; - -h | -help) + -h | -help*) usage ;; -o | -out) diff --git a/bin/foamUpdateCaseFileHeader b/bin/foamUpdateCaseFileHeader index 37d4e6d498..23a87a0c55 100755 --- a/bin/foamUpdateCaseFileHeader +++ b/bin/foamUpdateCaseFileHeader @@ -57,7 +57,7 @@ USAGE while [ "$#" -gt 0 ] do case "$1" in - -h | -help) + -h | -help*) usage ;; -v | -version) diff --git a/bin/mpirunDebug b/bin/mpirunDebug index 943ffee111..6cd3634e2a 100755 --- a/bin/mpirunDebug +++ b/bin/mpirunDebug @@ -75,7 +75,7 @@ while [ "$#" -gt 0 ] do # echo "$1" 1>&2 case "$1" in - -help) + -help*) usage ;; diff --git a/bin/paraFoam b/bin/paraFoam index 01e47e3066..6f1e2fe604 100755 --- a/bin/paraFoam +++ b/bin/paraFoam @@ -91,7 +91,7 @@ unset regionName optTouch while [ "$#" -gt 0 ] do case "$1" in - -h | -help) + -h | -help*) usage ;; -block*) diff --git a/bin/rmcore b/bin/rmcore index 8dde81b3cc..d5c0d4e1d1 100755 --- a/bin/rmcore +++ b/bin/rmcore @@ -29,18 +29,17 @@ # remove all core files #------------------------------------------------------------------------------ -# default is pwd -if [ "$#" -eq 0 ] -then - set -- . -elif [ "$1" = "-h" -o "$1" = "-help" ] -then +case "$1" in +-h | -help*) exec 1>&2 echo "Usage: ${0##*/} [dir1] .. [dirN]" echo " remove all core files" exit 1 -fi + ;; +esac +# Default is pwd +[ "$#" -gt 0 ] || set -- . for i do diff --git a/bin/rm~all b/bin/rm~all index c4fa742f89..4650d49754 100755 --- a/bin/rm~all +++ b/bin/rm~all @@ -29,18 +29,17 @@ # remove all *~ files #------------------------------------------------------------------------------ -# default is pwd -if [ "$#" -eq 0 ] -then - set -- . -elif [ "$1" = "-h" -o "$1" = "-help" ] -then +case "$1" in +-h | -help*) exec 1>&2 echo "Usage: ${0##*/} [dir1] .. [dirN]" echo " remove all *~ files" exit 1 -fi + ;; +esac +# default is pwd +[ "$#" -gt 0 ] || set -- . for i do diff --git a/bin/tools/foamConfigurePaths b/bin/tools/foamConfigurePaths index a17b6a033e..ffdbe117cf 100755 --- a/bin/tools/foamConfigurePaths +++ b/bin/tools/foamConfigurePaths @@ -182,7 +182,7 @@ unset adjusted optMpi while [ "$#" -gt 0 ] do case "$1" in - -h | -help | --help) + -h | -help* | --help*) usage ;; '') diff --git a/bin/tools/foamCreateCompletionCache b/bin/tools/foamCreateCompletionCache index 48f1e3449a..ee56d8cf44 100755 --- a/bin/tools/foamCreateCompletionCache +++ b/bin/tools/foamCreateCompletionCache @@ -77,7 +77,7 @@ unset outputFile while [ "$#" -gt 0 ] do case "$1" in - -h | -help) + -h | -help*) usage ;; -d | -dir) diff --git a/bin/tools/foamCreateModuleInclude b/bin/tools/foamCreateModuleInclude index 83877b495a..994b36e818 100755 --- a/bin/tools/foamCreateModuleInclude +++ b/bin/tools/foamCreateModuleInclude @@ -73,7 +73,7 @@ do '') # Ignore empty args ;; - -h | -help) + -h | -help*) usage ;; -debug) diff --git a/bin/tools/foamGrepExeTargets b/bin/tools/foamGrepExeTargets index b6b353d7fe..2fea5568f8 100755 --- a/bin/tools/foamGrepExeTargets +++ b/bin/tools/foamGrepExeTargets @@ -81,7 +81,7 @@ done while [ "$#" -gt 0 ] do case "$1" in - -h | -help) + -h | -help*) usage ;; diff --git a/doc/Doxygen/Allwmake b/doc/Doxygen/Allwmake index 21d606a9ab..a765bc363f 100755 --- a/doc/Doxygen/Allwmake +++ b/doc/Doxygen/Allwmake @@ -53,7 +53,7 @@ unset configName dirNames while [ "$#" -gt 0 ] do case "$1" in - -h | -help) + -h | -help*) usage ;; -config) diff --git a/etc/codeTemplates/foamScript b/etc/codeTemplates/foamScript index 02d8fb6c4a..983e38f90d 100755 --- a/etc/codeTemplates/foamScript +++ b/etc/codeTemplates/foamScript @@ -28,5 +28,49 @@ # Description # #------------------------------------------------------------------------------ +usage() { + exec 1>&2 + while [ "$#" -ge 1 ]; do echo "$1"; shift; done + cat<&2 + echo + echo "Error encountered:" + while [ "$#" -ge 1 ]; do echo " $1"; shift; done + echo + echo "See '${0##*/} -help' for usage" + echo + exit 1 +} + +#------------------------------------------------------------------------------- + +# Parse options + +while [ "$#" -gt 0 ] +do + case "$1" in + -h | -help*) + usage + ;; + *) + die "unknown option/argument: '$1'" + ;; + esac + shift +done + #------------------------------------------------------------------------------ diff --git a/etc/codeTemplates/source/foamNewSource b/etc/codeTemplates/source/foamNewSource index ae6d547141..1ece48d5ad 100755 --- a/etc/codeTemplates/source/foamNewSource +++ b/etc/codeTemplates/source/foamNewSource @@ -64,7 +64,7 @@ fi [ "$#" -gt 1 ] || usage case "$1" in -(-h | -help) +(-h | -help*) usage ;; (C|H) diff --git a/etc/codeTemplates/template/foamNewTemplate b/etc/codeTemplates/template/foamNewTemplate index a85be23b50..f46897ff18 100755 --- a/etc/codeTemplates/template/foamNewTemplate +++ b/etc/codeTemplates/template/foamNewTemplate @@ -65,7 +65,7 @@ fi case "$1" in -(-h | -help) +(-h | -help*) usage ;; (C|H) diff --git a/etc/config.sh/bash_completion b/etc/config.sh/bash_completion index 8d671ee9f7..2355f34087 100644 --- a/etc/config.sh/bash_completion +++ b/etc/config.sh/bash_completion @@ -92,9 +92,9 @@ foamAddCompletion() # - arg2 = current word # - arg3 = previous word # -# The respective options are generated on-the-fly from the application's -help -# output and cached to the _of_complete_cache_ global associative array with -# entries formatted as "argOpts.. | boolOpts ..". +# The respective options are generated on-the-fly from the application's +# -help-full output and cached to the _of_complete_cache_ global associative +# array with entries formatted as "argOpts.. | boolOpts ..". # The '|' character separates options with and without arguments. # unset -f _of_complete_ 2>/dev/null @@ -106,7 +106,7 @@ _of_complete_() local choices case ${prev} in - -help|-doc|-srcDoc) + -help|-help-full|-doc|-doc-source) # These options are usage - we can stop now. COMPREPLY=() return 0 @@ -130,10 +130,10 @@ _of_complete_() # All options choices="${_of_complete_cache_[$appName]}" - # Not in cache, obtain by parsing application -help + # Not in cache, obtain by parsing application -help-full if [ -z "$choices" ] then - local helpText=$($appName -help 2>/dev/null | sed -ne '/^ *-/p') + local helpText=$($appName -help-full 2>/dev/null | sed -ne '/^ *-/p') if [ -n "$helpText" ] then diff --git a/src/OpenFOAM/global/argList/argList.C b/src/OpenFOAM/global/argList/argList.C index e96e36ff09..2d53059de7 100644 --- a/src/OpenFOAM/global/argList/argList.C +++ b/src/OpenFOAM/global/argList/argList.C @@ -85,20 +85,20 @@ Foam::argList::initValidTables::initValidTables() argList::addBoolOption ( "noFunctionObjects", - "do not execute functionObjects" + "do not execute function objects" ); argList::addOption ( "fileHandler", "handler", - "override the fileHandler" + "override the file handler type" ); // Some standard option aliases (with or without version warnings) // argList::addOptionCompat // ( -// "noFunctionObjects", {"no-function-objects", 0 } +// "noFunctionObjects", {"no-function-objects", 0} // ); Pstream::addValidParOptions(validParOptions); @@ -152,8 +152,22 @@ static void printHostsSubscription(const UList& slaveProcs) Info<< ")" << nl; } + +// Print information about version, build, arch +static void printBuildInfo(const bool full=true) +{ + Info<<"Using: OpenFOAM-" << Foam::FOAMversion + << " (see www.OpenFOAM.com)" << nl + << "Build: " << Foam::FOAMbuild << nl; + + if (full) + { + Info << "Arch: " << Foam::FOAMbuildArch << nl; + } } +} // End namespace Foam + // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // @@ -415,9 +429,20 @@ Foam::word Foam::argList::optionCompat(const word& optionName) { const auto& iter = *canonical; - if (iter.second) + // Emit warning if there is versioning (non-zero) and it is not + // tagged as future change (ie, ThisVersion > version). + + if + ( + iter.second + && + ( + (OPENFOAM_PLUS > 1700) // Guard against bad #define value + ? (OPENFOAM_PLUS > iter.second) + : true + ) + ) { - // Emit warning, but only if version (non-zero) was provided std::cerr << "--> FOAM IOWarning :" << nl << " Found [v" << iter.second << "] '" @@ -614,6 +639,9 @@ Foam::argList::argList regroupArgv(argc, argv); argListStr_ += args_[0]; + // Set executable name immediately - useful when emitting errors. + executable_ = fileName(args_[0]).name(); + // Check arguments and options, argv[0] was already handled int nArgs = 1; HashTable::const_iterator optIter; @@ -649,11 +677,15 @@ Foam::argList::argList ++argi; if (argi >= args_.size()) { - FatalError - <<"Option '-" << optionName - << "' requires an argument" << endl; - printUsage(); - FatalError.exit(); + printBuildInfo(false); + + Info<