mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: consolidate handling of mandatory/optional command arguments
- for some special cases we wish to mark command-line arguments as
being optional, in order to do our own treatment. For example,
when an arbitrary number of arguments should be allowed.
Now tag this situation with argList::noMandatoryArgs().
The argList::argsMandatory() query can then be used in any further
logic, including the standard default argument checking.
- with the new default check, can consolidate the special-purpose
"setRootCaseNonMandatoryArgs.H"
into the regular
"setRootCase.H"
- revert to a simple "setRootCase.H" and move all the listing related
bits to a "setRootCaseLists.H" file. This leaves the information
available for solvers, or whoever else wishes, without being
introduced everywhere.
- add include guards and scoping to the listing files and rename to
something less generic.
listOptions.H -> setRootCaseListOptions.H
listOutput.H -> setRootCaseListOutput.H
This commit is contained in:
@ -373,12 +373,18 @@ void Foam::argList::removeOption(const word& optName)
|
||||
}
|
||||
|
||||
|
||||
void Foam::argList::nonMandatoryArgs()
|
||||
void Foam::argList::noMandatoryArgs()
|
||||
{
|
||||
argsMandatory_ = false;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::argList::argsMandatory()
|
||||
{
|
||||
return argsMandatory_;
|
||||
}
|
||||
|
||||
|
||||
void Foam::argList::noBanner()
|
||||
{
|
||||
::Foam::infoDetailLevel = 0;
|
||||
|
||||
@ -122,7 +122,7 @@ class argList
|
||||
{
|
||||
// Private data
|
||||
|
||||
//- Track enabled/disabled mandatory arguments
|
||||
//- Track if command arguments are mandatory/optional
|
||||
static bool argsMandatory_;
|
||||
|
||||
//- Track enabled/disabled checking of processor directories state
|
||||
@ -242,11 +242,15 @@ public:
|
||||
|
||||
//- Construct from argc and argv
|
||||
//- checking the arguments and options as requested.
|
||||
//
|
||||
// By default, the argument check respects the value of
|
||||
// argsMandatory() to decide if the arguments should be checked
|
||||
// (when they are mandatory) or not (when they are optional)
|
||||
argList
|
||||
(
|
||||
int& argc,
|
||||
char**& argv,
|
||||
bool checkArgs = true,
|
||||
bool checkArgs = argList::argsMandatory(),
|
||||
bool checkOpts = true,
|
||||
bool initialise = true
|
||||
);
|
||||
@ -463,8 +467,11 @@ public:
|
||||
//- Remove option from validOptions and from optionUsage
|
||||
static void removeOption(const word& optName);
|
||||
|
||||
//- Flag command arguments as being non-mandatory
|
||||
static void nonMandatoryArgs();
|
||||
//- Flag command arguments as being optional (non-mandatory)
|
||||
static void noMandatoryArgs();
|
||||
|
||||
//- Command arguments type (optional/mandatory).
|
||||
static bool argsMandatory();
|
||||
|
||||
//- Disable emitting the banner information.
|
||||
// Adjusts the Foam::infoDetailLevel flag.
|
||||
@ -527,8 +534,17 @@ public:
|
||||
|
||||
// Check
|
||||
|
||||
//- Check argument list
|
||||
bool check(bool checkArgs=true, bool checkOpts=true) const;
|
||||
//- Check the parsed command-line for mandatory arguments and
|
||||
//- that all the options are correct.
|
||||
//
|
||||
// By default, the argument check respects the value of
|
||||
// argsMandatory() to decide if the arguments should be checked
|
||||
// (when they are mandatory) or not (when they are optional)
|
||||
bool check
|
||||
(
|
||||
bool checkArgs = argList::argsMandatory(),
|
||||
bool checkOpts = true
|
||||
) const;
|
||||
|
||||
//- Check root path and case path
|
||||
bool checkRootCase() const;
|
||||
|
||||
@ -1,103 +0,0 @@
|
||||
bool listOptions = false;
|
||||
|
||||
if
|
||||
(
|
||||
args.found("listSwitches")
|
||||
)
|
||||
{
|
||||
debug::listSwitches(args.found("includeUnsetSwitches"));
|
||||
listOptions = true;
|
||||
}
|
||||
|
||||
if
|
||||
(
|
||||
args.found("listRegisteredSwitches")
|
||||
)
|
||||
{
|
||||
debug::listRegisteredSwitches(args.found("includeUnsetSwitches"));
|
||||
listOptions = true;
|
||||
}
|
||||
|
||||
#ifdef fvPatchField_H
|
||||
if (args.found("listScalarBCs"))
|
||||
{
|
||||
Info<< "scalarBCs"
|
||||
<< fvPatchField<scalar>::dictionaryConstructorTablePtr_->sortedToc()
|
||||
<< endl;
|
||||
listOptions = true;
|
||||
}
|
||||
|
||||
if (args.found("listVectorBCs"))
|
||||
{
|
||||
Info<< "vectorBCs"
|
||||
<< fvPatchField<Foam::vector>::
|
||||
dictionaryConstructorTablePtr_->sortedToc()
|
||||
<< endl;
|
||||
listOptions = true;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef functionObject_H
|
||||
if (args.found("listFunctionObjects"))
|
||||
{
|
||||
Info<< "functionObjects"
|
||||
<< functionObject::dictionaryConstructorTablePtr_->sortedToc()
|
||||
<< endl;
|
||||
listOptions = true;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef fvOption_H
|
||||
if (args.found("listFvOptions"))
|
||||
{
|
||||
Info<< "fvOptions"
|
||||
<< fv::option::dictionaryConstructorTablePtr_->sortedToc()
|
||||
<< endl;
|
||||
listOptions = true;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef turbulentTransportModel_H
|
||||
if (args.found("listTurbulenceModels"))
|
||||
{
|
||||
Info<< "Turbulence models"
|
||||
<< incompressible::turbulenceModel::
|
||||
dictionaryConstructorTablePtr_->sortedToc()
|
||||
<< endl;
|
||||
|
||||
Info<< "RAS models"
|
||||
<< incompressible::RASModel::
|
||||
dictionaryConstructorTablePtr_->sortedToc()
|
||||
<< endl;
|
||||
|
||||
Info<< "LES models"
|
||||
<< incompressible::LESModel::
|
||||
dictionaryConstructorTablePtr_->sortedToc()
|
||||
<< endl;
|
||||
listOptions = true;
|
||||
}
|
||||
#elif defined(turbulentFluidThermoModel_H)
|
||||
if (args.found("listTurbulenceModels"))
|
||||
{
|
||||
Info<< "Turbulence models"
|
||||
<< compressible::turbulenceModel::
|
||||
dictionaryConstructorTablePtr_->sortedToc()
|
||||
<< endl;
|
||||
|
||||
Info<< "RAS models"
|
||||
<< compressible::RASModel::
|
||||
dictionaryConstructorTablePtr_->sortedToc()
|
||||
<< endl;
|
||||
|
||||
Info<< "LES models"
|
||||
<< compressible::LESModel::
|
||||
dictionaryConstructorTablePtr_->sortedToc()
|
||||
<< endl;
|
||||
listOptions = true;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (listOptions)
|
||||
{
|
||||
exit(0);
|
||||
}
|
||||
@ -1,4 +1,6 @@
|
||||
#include "listOptions.H"
|
||||
// Construct from (int argc, char* argv[]),
|
||||
// - use argList::argsMandatory() to decide on checking command arguments.
|
||||
// - check validity of the options
|
||||
|
||||
Foam::argList args(argc, argv);
|
||||
if (!args.checkRootCase())
|
||||
@ -6,4 +8,10 @@ if (!args.checkRootCase())
|
||||
Foam::FatalError.exit();
|
||||
}
|
||||
|
||||
#include "listOutput.H"
|
||||
// User can also perform checks on otherwise optional arguments.
|
||||
// Eg,
|
||||
//
|
||||
// if (!args.check(true, false))
|
||||
// {
|
||||
// Foam::FatalError.exit();
|
||||
// }
|
||||
|
||||
@ -1,3 +1,9 @@
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
// Declare some "standard" list options
|
||||
|
||||
#ifndef setRootCaseListOptions_H
|
||||
#define setRootCaseListOptions_H
|
||||
|
||||
argList::addBoolOption
|
||||
(
|
||||
"listSwitches",
|
||||
@ -58,3 +64,10 @@ argList::addBoolOption
|
||||
true // advanced
|
||||
);
|
||||
#endif
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
113
src/OpenFOAM/include/setRootCaseListOutput.H
Normal file
113
src/OpenFOAM/include/setRootCaseListOutput.H
Normal file
@ -0,0 +1,113 @@
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
// Process some "standard" list options
|
||||
|
||||
#ifndef setRootCaseListOutput_H
|
||||
#define setRootCaseListOutput_H
|
||||
|
||||
{
|
||||
bool listOptions = false;
|
||||
|
||||
if (args.found("listSwitches"))
|
||||
{
|
||||
debug::listSwitches(args.found("includeUnsetSwitches"));
|
||||
listOptions = true;
|
||||
}
|
||||
|
||||
if (args.found("listRegisteredSwitches"))
|
||||
{
|
||||
debug::listRegisteredSwitches(args.found("includeUnsetSwitches"));
|
||||
listOptions = true;
|
||||
}
|
||||
|
||||
#ifdef fvPatchField_H
|
||||
if (args.found("listScalarBCs"))
|
||||
{
|
||||
Info<< "scalarBCs"
|
||||
<< fvPatchField<Foam::scalar>::
|
||||
dictionaryConstructorTablePtr_->sortedToc()
|
||||
<< endl;
|
||||
listOptions = true;
|
||||
}
|
||||
|
||||
if (args.found("listVectorBCs"))
|
||||
{
|
||||
Info<< "vectorBCs"
|
||||
<< fvPatchField<Foam::vector>::
|
||||
dictionaryConstructorTablePtr_->sortedToc()
|
||||
<< endl;
|
||||
listOptions = true;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef functionObject_H
|
||||
if (args.found("listFunctionObjects"))
|
||||
{
|
||||
Info<< "functionObjects"
|
||||
<< functionObject::dictionaryConstructorTablePtr_->sortedToc()
|
||||
<< endl;
|
||||
listOptions = true;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef fvOption_H
|
||||
if (args.found("listFvOptions"))
|
||||
{
|
||||
Info<< "fvOptions"
|
||||
<< fv::option::dictionaryConstructorTablePtr_->sortedToc()
|
||||
<< endl;
|
||||
listOptions = true;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef turbulentTransportModel_H
|
||||
if (args.found("listTurbulenceModels"))
|
||||
{
|
||||
Info<< "Turbulence models"
|
||||
<< incompressible::turbulenceModel::
|
||||
dictionaryConstructorTablePtr_->sortedToc()
|
||||
<< endl;
|
||||
|
||||
Info<< "RAS models"
|
||||
<< incompressible::RASModel::
|
||||
dictionaryConstructorTablePtr_->sortedToc()
|
||||
<< endl;
|
||||
|
||||
Info<< "LES models"
|
||||
<< incompressible::LESModel::
|
||||
dictionaryConstructorTablePtr_->sortedToc()
|
||||
<< endl;
|
||||
listOptions = true;
|
||||
}
|
||||
#elif defined(turbulentFluidThermoModel_H)
|
||||
if (args.found("listTurbulenceModels"))
|
||||
{
|
||||
Info<< "Turbulence models"
|
||||
<< compressible::turbulenceModel::
|
||||
dictionaryConstructorTablePtr_->sortedToc()
|
||||
<< endl;
|
||||
|
||||
Info<< "RAS models"
|
||||
<< compressible::RASModel::
|
||||
dictionaryConstructorTablePtr_->sortedToc()
|
||||
<< endl;
|
||||
|
||||
Info<< "LES models"
|
||||
<< compressible::LESModel::
|
||||
dictionaryConstructorTablePtr_->sortedToc()
|
||||
<< endl;
|
||||
listOptions = true;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (listOptions)
|
||||
{
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
5
src/OpenFOAM/include/setRootCaseLists.H
Normal file
5
src/OpenFOAM/include/setRootCaseLists.H
Normal file
@ -0,0 +1,5 @@
|
||||
// This is setRootCase, but with additional solver-related listing
|
||||
|
||||
#include "setRootCaseListOptions.H"
|
||||
#include "setRootCase.H"
|
||||
#include "setRootCaseListOutput.H"
|
||||
@ -1,21 +0,0 @@
|
||||
// As per "setRootCase.H", but used when command-arguments are non-mandatory
|
||||
|
||||
Foam::argList::nonMandatoryArgs();
|
||||
|
||||
#include "listOptions.H"
|
||||
|
||||
Foam::argList args(argc, argv, false); // With suppressed check for arguments
|
||||
if (!args.checkRootCase())
|
||||
{
|
||||
Foam::FatalError.exit();
|
||||
}
|
||||
|
||||
#include "listOutput.H"
|
||||
|
||||
//// Any subsequent user code will need to perform any pending checks
|
||||
//// on arguments. Eg,
|
||||
//
|
||||
// if (!args.check(true, false))
|
||||
// {
|
||||
// FatalError.exit();
|
||||
// }
|
||||
Reference in New Issue
Block a user