From c89e13f82f330246060788e2a94f00e6dcebfb04 Mon Sep 17 00:00:00 2001 From: Mark Olesen <Mark.Olesen@esi-group.com> Date: Mon, 30 Jul 2018 08:58:36 +0200 Subject: [PATCH] ENH: allow command-line options to be tagged as "advanced" - advanced options are not displayed with -help, but only with -help-full, which helps retain a better overview of the standard options. Replaces previous ad hoc suppression of -listSwitches, -listRegisteredSwitches etc. --- src/OpenFOAM/global/argList/argList.C | 31 ++++++++++++++------------- src/OpenFOAM/global/argList/argList.H | 10 +++++++-- src/OpenFOAM/include/listOptions.H | 24 ++++++++++++++------- src/OpenFOAM/include/listOutput.H | 2 +- 4 files changed, 41 insertions(+), 26 deletions(-) diff --git a/src/OpenFOAM/global/argList/argList.C b/src/OpenFOAM/global/argList/argList.C index d550a005168..7957bb66679 100644 --- a/src/OpenFOAM/global/argList/argList.C +++ b/src/OpenFOAM/global/argList/argList.C @@ -52,6 +52,7 @@ License bool Foam::argList::argsMandatory_ = true; bool Foam::argList::checkProcessorDirectories_ = true; Foam::SLList<Foam::string> Foam::argList::validArgs; +Foam::HashSet<Foam::string> Foam::argList::advancedOptions; Foam::HashTable<Foam::string> Foam::argList::validOptions; Foam::HashTable<Foam::string> Foam::argList::validParOptions; Foam::HashTable<Foam::string> Foam::argList::optionUsage; @@ -234,10 +235,11 @@ void Foam::argList::addArgument(const string& argName) void Foam::argList::addBoolOption ( const word& optName, - const string& usage + const string& usage, + const bool advanced ) { - addOption(optName, "", usage); + addOption(optName, "", usage, advanced); } @@ -245,7 +247,8 @@ void Foam::argList::addOption ( const word& optName, const string& param, - const string& usage + const string& usage, + const bool advanced ) { validOptions.set(optName, param); @@ -253,6 +256,10 @@ void Foam::argList::addOption { optionUsage.set(optName, usage); } + if (advanced) + { + advancedOptions.set(optName); + } } @@ -314,6 +321,7 @@ void Foam::argList::removeOption(const word& optName) { validOptions.erase(optName); optionUsage.erase(optName); + advancedOptions.erase(optName); } @@ -361,7 +369,8 @@ void Foam::argList::noLibs() addBoolOption ( "no-libs", - "disable use of the controlDict libs entry" + "disable use of the controlDict libs entry", + true // advanced ); } @@ -427,7 +436,7 @@ void Foam::argList::printOptionUsage else if (isspace(str[curr+1])) { // The next one is a space - so we are okay - curr++; // otherwise the length is wrong + ++curr; // otherwise the length is wrong next = str.find_first_not_of(" \t\n", curr); } else @@ -1575,16 +1584,8 @@ void Foam::argList::printUsage(bool full) const for (const word& optName : validOptions.sortedToc()) { - // Ad hoc suppression of some options for regular (non-full) help - if - ( - !full - && - ( - // '-listXXX' and '-list-XXX' but not '-list' - (optName.size() > 4 && optName.startsWith("list")) - ) - ) + // Suppress advanced options for regular -help. + if (advancedOptions.found(optName) && !full) { continue; } diff --git a/src/OpenFOAM/global/argList/argList.H b/src/OpenFOAM/global/argList/argList.H index 7795e892707..aff7e50d3e3 100644 --- a/src/OpenFOAM/global/argList/argList.H +++ b/src/OpenFOAM/global/argList/argList.H @@ -97,6 +97,7 @@ SourceFiles #include "stringList.H" #include "SubList.H" #include "SLList.H" +#include "HashSet.H" #include "HashTable.H" #include "word.H" #include "fileName.H" @@ -193,6 +194,9 @@ public: //- A list of valid (mandatory) arguments static SLList<string> validArgs; + //- The "advanced" options are shown with -help-full (not with --help) + static HashSet<string> advancedOptions; + //- A list of valid options static HashTable<string> validOptions; @@ -386,7 +390,8 @@ public: static void addBoolOption ( const word& optName, - const string& usage = "" + const string& usage = "", + const bool advanced = false ); //- Add an option to validOptions with usage information @@ -395,7 +400,8 @@ public: ( const word& optName, const string& param = "", - const string& usage = "" + const string& usage = "", + const bool advanced = false ); //- Specify an alias for the option name. diff --git a/src/OpenFOAM/include/listOptions.H b/src/OpenFOAM/include/listOptions.H index 49131de763c..a9c32687543 100644 --- a/src/OpenFOAM/include/listOptions.H +++ b/src/OpenFOAM/include/listOptions.H @@ -1,29 +1,34 @@ argList::addBoolOption ( "listSwitches", - "List switches declared in libraries but not set in etc/controlDict" + "List switches declared in libraries but not set in etc/controlDict", + true // advanced ); argList::addBoolOption ( "listRegisteredSwitches", - "List switches registered for run-time modification" + "List switches registered for run-time modification", + true // advanced ); argList::addBoolOption ( "listUnsetSwitches", - "List switches declared in libraries but not set in etc/controlDict" + "List switches declared in libraries but not set in etc/controlDict", + true // advanced ); #ifdef fvPatchField_H argList::addBoolOption ( "listScalarBCs", - "List scalar field boundary conditions (fvPatchField<scalar>)" + "List scalar field boundary conditions (fvPatchField<scalar>)", + true // advanced ); argList::addBoolOption ( "listVectorBCs", - "List vector field boundary conditions (fvPatchField<vector>)" + "List vector field boundary conditions (fvPatchField<vector>)", + true // advanced ); #endif @@ -31,7 +36,8 @@ argList::addBoolOption argList::addBoolOption ( "listFunctionObjects", - "List functionObjects" + "List functionObjects", + true // advanced ); #endif @@ -39,7 +45,8 @@ argList::addBoolOption argList::addBoolOption ( "listFvOptions", - "List fvOptions" + "List fvOptions", + true // advanced ); #endif @@ -47,6 +54,7 @@ argList::addBoolOption argList::addBoolOption ( "listTurbulenceModels", - "List turbulenceModels" + "List turbulenceModels", + true // advanced ); #endif diff --git a/src/OpenFOAM/include/listOutput.H b/src/OpenFOAM/include/listOutput.H index 99057484e2a..77553615f75 100644 --- a/src/OpenFOAM/include/listOutput.H +++ b/src/OpenFOAM/include/listOutput.H @@ -1,4 +1,4 @@ -bool listOptions = false ; +bool listOptions = false; if ( -- GitLab