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.
This commit is contained in:
Mark Olesen
2018-07-30 08:58:36 +02:00
parent 14447e4cc6
commit c89e13f82f
4 changed files with 41 additions and 26 deletions

View File

@ -52,6 +52,7 @@ License
bool Foam::argList::argsMandatory_ = true; bool Foam::argList::argsMandatory_ = true;
bool Foam::argList::checkProcessorDirectories_ = true; bool Foam::argList::checkProcessorDirectories_ = true;
Foam::SLList<Foam::string> Foam::argList::validArgs; 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::validOptions;
Foam::HashTable<Foam::string> Foam::argList::validParOptions; Foam::HashTable<Foam::string> Foam::argList::validParOptions;
Foam::HashTable<Foam::string> Foam::argList::optionUsage; Foam::HashTable<Foam::string> Foam::argList::optionUsage;
@ -234,10 +235,11 @@ void Foam::argList::addArgument(const string& argName)
void Foam::argList::addBoolOption void Foam::argList::addBoolOption
( (
const word& optName, 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 word& optName,
const string& param, const string& param,
const string& usage const string& usage,
const bool advanced
) )
{ {
validOptions.set(optName, param); validOptions.set(optName, param);
@ -253,6 +256,10 @@ void Foam::argList::addOption
{ {
optionUsage.set(optName, usage); optionUsage.set(optName, usage);
} }
if (advanced)
{
advancedOptions.set(optName);
}
} }
@ -314,6 +321,7 @@ void Foam::argList::removeOption(const word& optName)
{ {
validOptions.erase(optName); validOptions.erase(optName);
optionUsage.erase(optName); optionUsage.erase(optName);
advancedOptions.erase(optName);
} }
@ -361,7 +369,8 @@ void Foam::argList::noLibs()
addBoolOption addBoolOption
( (
"no-libs", "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])) else if (isspace(str[curr+1]))
{ {
// The next one is a space - so we are okay // 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); next = str.find_first_not_of(" \t\n", curr);
} }
else else
@ -1575,16 +1584,8 @@ void Foam::argList::printUsage(bool full) const
for (const word& optName : validOptions.sortedToc()) for (const word& optName : validOptions.sortedToc())
{ {
// Ad hoc suppression of some options for regular (non-full) help // Suppress advanced options for regular -help.
if if (advancedOptions.found(optName) && !full)
(
!full
&&
(
// '-listXXX' and '-list-XXX' but not '-list'
(optName.size() > 4 && optName.startsWith("list"))
)
)
{ {
continue; continue;
} }

View File

@ -97,6 +97,7 @@ SourceFiles
#include "stringList.H" #include "stringList.H"
#include "SubList.H" #include "SubList.H"
#include "SLList.H" #include "SLList.H"
#include "HashSet.H"
#include "HashTable.H" #include "HashTable.H"
#include "word.H" #include "word.H"
#include "fileName.H" #include "fileName.H"
@ -193,6 +194,9 @@ public:
//- A list of valid (mandatory) arguments //- A list of valid (mandatory) arguments
static SLList<string> validArgs; static SLList<string> validArgs;
//- The "advanced" options are shown with -help-full (not with --help)
static HashSet<string> advancedOptions;
//- A list of valid options //- A list of valid options
static HashTable<string> validOptions; static HashTable<string> validOptions;
@ -386,7 +390,8 @@ public:
static void addBoolOption static void addBoolOption
( (
const word& optName, const word& optName,
const string& usage = "" const string& usage = "",
const bool advanced = false
); );
//- Add an option to validOptions with usage information //- Add an option to validOptions with usage information
@ -395,7 +400,8 @@ public:
( (
const word& optName, const word& optName,
const string& param = "", const string& param = "",
const string& usage = "" const string& usage = "",
const bool advanced = false
); );
//- Specify an alias for the option name. //- Specify an alias for the option name.

View File

@ -1,29 +1,34 @@
argList::addBoolOption argList::addBoolOption
( (
"listSwitches", "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 argList::addBoolOption
( (
"listRegisteredSwitches", "listRegisteredSwitches",
"List switches registered for run-time modification" "List switches registered for run-time modification",
true // advanced
); );
argList::addBoolOption argList::addBoolOption
( (
"listUnsetSwitches", "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 #ifdef fvPatchField_H
argList::addBoolOption argList::addBoolOption
( (
"listScalarBCs", "listScalarBCs",
"List scalar field boundary conditions (fvPatchField<scalar>)" "List scalar field boundary conditions (fvPatchField<scalar>)",
true // advanced
); );
argList::addBoolOption argList::addBoolOption
( (
"listVectorBCs", "listVectorBCs",
"List vector field boundary conditions (fvPatchField<vector>)" "List vector field boundary conditions (fvPatchField<vector>)",
true // advanced
); );
#endif #endif
@ -31,7 +36,8 @@ argList::addBoolOption
argList::addBoolOption argList::addBoolOption
( (
"listFunctionObjects", "listFunctionObjects",
"List functionObjects" "List functionObjects",
true // advanced
); );
#endif #endif
@ -39,7 +45,8 @@ argList::addBoolOption
argList::addBoolOption argList::addBoolOption
( (
"listFvOptions", "listFvOptions",
"List fvOptions" "List fvOptions",
true // advanced
); );
#endif #endif
@ -47,6 +54,7 @@ argList::addBoolOption
argList::addBoolOption argList::addBoolOption
( (
"listTurbulenceModels", "listTurbulenceModels",
"List turbulenceModels" "List turbulenceModels",
true // advanced
); );
#endif #endif

View File

@ -1,4 +1,4 @@
bool listOptions = false ; bool listOptions = false;
if if
( (