ENH: support usage descriptions for command arguments

This commit is contained in:
Mark Olesen
2018-12-12 11:58:56 +01:00
parent c3b6c787a7
commit f38190213c
49 changed files with 256 additions and 110 deletions

View File

@ -350,7 +350,11 @@ int main(int argc, char *argv[])
#include "addOverwriteOption.H" #include "addOverwriteOption.H"
argList::addArgument("featureAngle [0..180]"); argList::addArgument
(
"featureAngle",
"in degrees [0-180]"
);
argList::addOption argList::addOption
( (
"concaveAngle", "concaveAngle",
@ -360,7 +364,7 @@ int main(int argc, char *argv[])
argList::addBoolOption argList::addBoolOption
( (
"meshQuality", "meshQuality",
"Read user-defined mesh quality criterions from system/meshQualityDict" "Read user-defined mesh quality criteria from system/meshQualityDict"
); );
argList::noFunctionObjects(); // Never use function objects argList::noFunctionObjects(); // Never use function objects
@ -411,7 +415,7 @@ int main(int argc, char *argv[])
IOobject::MUST_READ, IOobject::MUST_READ,
IOobject::NO_WRITE IOobject::NO_WRITE
) )
) )
); );
} }

View File

@ -31,7 +31,7 @@ Description
Refine cells next to specified patches. Refine cells next to specified patches.
Arguments: Arguments:
1: List of patch name regular expressions 1: List of patch names or regular expressions
2: The size of the refined cells as a fraction of the edge-length. 2: The size of the refined cells as a fraction of the edge-length.
Examples: Examples:
@ -63,13 +63,21 @@ int main(int argc, char *argv[])
{ {
argList::addNote argList::addNote
( (
"Refine cells next to specified patches.\n" "Refine cells next to specified patches."
"The list of patches may contain regular expressions.\n"
); );
#include "addOverwriteOption.H" #include "addOverwriteOption.H"
argList::addArgument("patches"); argList::addArgument
argList::addArgument("edgeFraction"); (
"patches",
"The list of patch names or regex - Eg, '(top \"Wall.\")'"
);
argList::addArgument
(
"edgeFraction",
"The size of the refined cells as a fraction of the edge-length"
" on a (0,1) interval"
);
argList::addOption argList::addOption
( (

View File

@ -526,7 +526,11 @@ int main(int argc, char *argv[])
); );
#include "addOverwriteOption.H" #include "addOverwriteOption.H"
argList::noParallel(); argList::noParallel();
argList::addArgument("edgeAngle [0..360]"); argList::addArgument
(
"edgeAngle",
"in degrees [0-360]"
);
argList::addOption argList::addOption
( (

View File

@ -99,7 +99,7 @@ int main(int argc, char *argv[])
); );
argList::noParallel(); argList::noParallel();
argList::addArgument("ccmMesh"); argList::addArgument("ccm-file", "The input .ccm or .ccmg file");
argList::addBoolOption argList::addBoolOption
( (
"ascii", "ascii",

View File

@ -64,7 +64,7 @@ int main(int argc, char *argv[])
); );
argList::noParallel(); argList::noParallel();
argList::addArgument("firePolyMesh"); argList::addArgument("firePolyMesh", "The input FIRE mesh");
argList::addBoolOption argList::addBoolOption
( (
"ascii", "ascii",

View File

@ -61,7 +61,8 @@ int main(int argc, char *argv[])
"Extract boundaries from an OpenFOAM mesh and write in a surface format" "Extract boundaries from an OpenFOAM mesh and write in a surface format"
); );
argList::noParallel(); argList::noParallel();
argList::addArgument("outputFile.ext"); argList::addArgument("output", "The output surface file");
timeSelector::addOptions(); timeSelector::addOptions();
argList::addOption argList::addOption

View File

@ -70,7 +70,7 @@ int main(int argc, char *argv[])
); );
argList::noParallel(); argList::noParallel();
argList::addArgument("PROSTAR prefix"); argList::addArgument("prefix", "The prefix for the input PROSTAR files");
argList::addBoolOption argList::addBoolOption
( (
"ascii", "ascii",

View File

@ -106,7 +106,7 @@ int main(int argc, char *argv[])
"Convert tetgen .ele and .node and .face files to an OpenFOAM mesh" "Convert tetgen .ele and .node and .face files to an OpenFOAM mesh"
); );
argList::addArgument("file prefix"); argList::addArgument("prefix", "The prefix for the input tetgen files");
argList::addBoolOption argList::addBoolOption
( (
"noFaceFile", "noFaceFile",

View File

@ -58,7 +58,7 @@ int main(int argc, char *argv[])
); );
argList::noParallel(); argList::noParallel();
argList::addArgument(".vtk ascii file"); argList::addArgument("vtk-file", "The input legacy ascii vtk file");
#include "setRootCase.H" #include "setRootCase.H"
#include "createTime.H" #include "createTime.H"

View File

@ -369,7 +369,7 @@ int main(int argc, char *argv[])
"Re-sample surfaces used in foamyHexMesh operation" "Re-sample surfaces used in foamyHexMesh operation"
); );
argList::addArgument("outputName"); argList::addArgument("output", "The output triSurface/ file");
argList::noFunctionObjects(); // Never use function objects argList::noFunctionObjects(); // Never use function objects

View File

@ -53,8 +53,8 @@ int main(int argc, char *argv[])
( (
"Re-sample surfaces used in foamyHexMesh operation" "Re-sample surfaces used in foamyHexMesh operation"
); );
argList::addArgument("(nx ny nz)"); argList::addArgument("(nx ny nz)", "The resampling interval");
argList::addArgument("outputName"); argList::addArgument("output", "The output triSurface/ file");
argList::noFunctionObjects(); // Never use function objects argList::noFunctionObjects(); // Never use function objects

View File

@ -83,7 +83,7 @@ int main(int argc, char *argv[])
argList::noParallel(); argList::noParallel();
argList::noFunctionObjects(); // Never use function objects argList::noFunctionObjects(); // Never use function objects
argList::addArgument("feature angle[0-180]"); argList::addArgument("featureAngle", "in degrees [0-180]");
#include "setRootCase.H" #include "setRootCase.H"
#include "createTime.H" #include "createTime.H"

View File

@ -50,7 +50,7 @@ int main(int argc, char *argv[])
" supplied as an argument" " supplied as an argument"
); );
argList::addArgument("scaling factor"); argList::addArgument("factor", "The deformation scaling factor");
#include "setRootCase.H" #include "setRootCase.H"

View File

@ -116,8 +116,8 @@ int main(int argc, char *argv[])
); );
argList::noParallel(); argList::noParallel();
argList::addArgument("OBJ file"); argList::addArgument("obj-file", "The input obj line file");
argList::addArgument("output VTK file"); argList::addArgument("vtk-file", "The output vtk file");
argList args(argc, argv); argList args(argc, argv);
const fileName objName = args[1]; const fileName objName = args[1];

View File

@ -28,7 +28,7 @@ Group
grpMeshManipulationUtilities grpMeshManipulationUtilities
Description Description
Corrects teh orientation of faceZone. Corrects the orientation of faceZone.
- correct in parallel - excludes coupled faceZones from walk - correct in parallel - excludes coupled faceZones from walk
- correct for non-manifold faceZones - restarts walk - correct for non-manifold faceZones - restarts walk
@ -55,7 +55,7 @@ int main(int argc, char *argv[])
); );
#include "addRegionOption.H" #include "addRegionOption.H"
argList::addArgument("faceZone"); argList::addArgument("faceZone");
argList::addArgument("outsidePoint"); argList::addArgument("point", "A point outside of the mesh");
#include "setRootCase.H" #include "setRootCase.H"
#include "createTime.H" #include "createTime.H"

View File

@ -368,7 +368,12 @@ int main(int argc, char *argv[])
#include "addOverwriteOption.H" #include "addOverwriteOption.H"
argList::noParallel(); argList::noParallel();
argList::addArgument("featureAngle [0-180]"); argList::addArgument
(
"featureAngle",
"in degrees [0-180]"
);
argList::addBoolOption argList::addBoolOption
( (
"splitAllFaces", "splitAllFaces",

View File

@ -72,13 +72,13 @@ int main(int argc, char *argv[])
argList::addNote argList::addNote
( (
"Rotate mesh points and vector/tensor fields\n" "Rotate mesh points and vector/tensor fields\n"
"Rotation from the <n1> vector to the <n2> vector" "Rotation from the <from> vector to the <to> vector"
); );
timeSelector::addOptions(); timeSelector::addOptions();
argList::addArgument("n1"); argList::addArgument("from", "The vector to rotate from");
argList::addArgument("n2"); argList::addArgument("to", "The vector to rotate to");
#include "setRootCase.H" #include "setRootCase.H"
#include "createTime.H" #include "createTime.H"

View File

@ -123,9 +123,9 @@ int main(int argc, char *argv[])
#include "addOverwriteOption.H" #include "addOverwriteOption.H"
argList::addArgument("faceSet"); argList::addArgument("faceSet", "The faces used for splitting");
argList::addArgument("masterPatch"); argList::addArgument("master", "The master patch name");
argList::addArgument("slavePatch"); argList::addArgument("slave", "The slave patch name");
#include "setRootCase.H" #include "setRootCase.H"
#include "createTime.H" #include "createTime.H"

View File

@ -145,8 +145,16 @@ int main(int argc, char *argv[])
); );
// The arguments are non-mandatory when using dictionary mode // The arguments are non-mandatory when using dictionary mode
argList::addArgument("masterPatch"); argList::addArgument
argList::addArgument("slavePatch"); (
"master",
"The master patch name (non-dictionary mode)"
);
argList::addArgument
(
"slave",
"The slave patch name (non-dictionary mode)"
);
#include "setRootCaseNonMandatoryArgs.H" #include "setRootCaseNonMandatoryArgs.H"

View File

@ -269,7 +269,7 @@ int main(int argc, char *argv[])
argList::noBanner(); argList::noBanner();
argList::noJobInfo(); argList::noJobInfo();
argList::addArgument("dictionary"); argList::addArgument("dict", "The dictionary file to process");
argList::addBoolOption("keywords", "List keywords"); argList::addBoolOption("keywords", "List keywords");
argList::addOption("entry", "name", "Report/select the named entry"); argList::addOption("entry", "name", "Report/select the named entry");
argList::addBoolOption argList::addBoolOption

View File

@ -56,9 +56,9 @@ int main(int argc, char *argv[])
); );
argList::noParallel(); argList::noParallel();
argList::addArgument("surfaceFile"); argList::addArgument("surface1", "The input surface file 1");
argList::addArgument("surfaceFile"); argList::addArgument("surface2", "The input surface file 2");
argList::addArgument("output surfaceFile"); argList::addArgument("output", "The output surface file");
argList::addOption argList::addOption
( (

View File

@ -1509,14 +1509,18 @@ int main(int argc, char *argv[])
{ {
argList::addNote argList::addNote
( (
"Generates the extendedFeatureEdgeMesh for the interface between" "Generates the extendedFeatureEdgeMesh for the interface created by"
" a boolean operation on two surfaces." " a boolean operation on two surfaces."
); );
argList::noParallel(); argList::noParallel();
argList::addArgument("action"); argList::addArgument
argList::addArgument("surfaceFile1"); (
argList::addArgument("surfaceFile2"); "action",
"One of (intersection | union | difference)"
);
argList::addArgument("surface1", "The input surface file 1");
argList::addArgument("surface2", "The input surface file 2");
argList::addOption argList::addOption
( (
@ -1560,12 +1564,6 @@ int main(int argc, char *argv[])
" 'mixed' (keep all)" " 'mixed' (keep all)"
); );
argList::addNote
(
"Valid actions: \"intersection\", \"union\", \"difference\""
);
#include "setRootCase.H" #include "setRootCase.H"
#include "createTime.H" #include "createTime.H"

View File

@ -323,7 +323,8 @@ int main(int argc, char *argv[])
); );
argList::noParallel(); argList::noParallel();
argList::addArgument("surfaceFile"); argList::addArgument("input", "The input surface file");
argList::addBoolOption argList::addBoolOption
( (
"checkSelfIntersection", "checkSelfIntersection",

View File

@ -59,10 +59,11 @@ int main(int argc, char *argv[])
); );
argList::noParallel(); argList::noParallel();
argList::addArgument("surfaceFile"); argList::addArgument("input", "The input surface file");
argList::addArgument("min length"); argList::addArgument("length", "The min length");
argList::addArgument("min quality"); argList::addArgument("quality", "The min quality");
argList::addArgument("output surfaceFile"); argList::addArgument("output", "The output surface file");
argList::addBoolOption argList::addBoolOption
( (
"noClean", "noClean",

View File

@ -77,9 +77,9 @@ int main(int argc, char *argv[])
); );
argList::noParallel(); argList::noParallel();
argList::addArgument("surfaceFile"); argList::addArgument("input", "The input surface file");
argList::addArgument("reductionFactor"); argList::addArgument("factor", "The reduction factor [0,1)");
argList::addArgument("output surfaceFile"); argList::addArgument("output", "The output surface file");
argList::addOption argList::addOption
( (
"scale", "scale",

View File

@ -68,8 +68,8 @@ int main(int argc, char *argv[])
); );
argList::noParallel(); argList::noParallel();
argList::addArgument("inputFile"); argList::addArgument("input", "The input surface file");
argList::addArgument("outputFile"); argList::addArgument("output", "The output surface file");
argList::addBoolOption argList::addBoolOption
( (

View File

@ -49,8 +49,8 @@ int main(int argc, char *argv[])
"Convert between edgeMesh formats" "Convert between edgeMesh formats"
); );
argList::noParallel(); argList::noParallel();
argList::addArgument("inputFile"); argList::addArgument("input", "The input edge file");
argList::addArgument("outputFile"); argList::addArgument("output", "The output edge file");
argList::addOption argList::addOption
( (
"scale", "scale",

View File

@ -52,7 +52,7 @@ int main(int argc, char *argv[])
); );
argList::noParallel(); argList::noParallel();
argList::addArgument("surfaceFile"); argList::addArgument("input", "The input surface file");
argList::addOption("x", "X", "The point x-coordinate (if non-zero)"); argList::addOption("x", "X", "The point x-coordinate (if non-zero)");
argList::addOption("y", "Y", "The point y-coordinate (if non-zero)"); argList::addOption("y", "Y", "The point y-coordinate (if non-zero)");
argList::addOption("z", "Z", "The point y-coordinate (if non-zero)"); argList::addOption("z", "Z", "The point y-coordinate (if non-zero)");

View File

@ -273,7 +273,7 @@ int main(int argc, char *argv[])
" boundary edges to match other surface boundary edges" " boundary edges to match other surface boundary edges"
); );
argList::noParallel(); argList::noParallel();
argList::addArgument("hookTolerance"); argList::addArgument("hookTolerance", "The point merge tolerance");
#include "addDictOption.H" #include "addDictOption.H"

View File

@ -60,7 +60,8 @@ int main(int argc, char *argv[])
); );
argList::noParallel(); argList::noParallel();
argList::addArgument("surfaceFile"); argList::addArgument("input", "The input surface file");
argList::addBoolOption argList::addBoolOption
( (
"shellProperties", "shellProperties",

View File

@ -597,9 +597,9 @@ int main(int argc, char *argv[])
"Switch on additional debug information" "Switch on additional debug information"
); );
argList::addArgument("inputFile"); argList::addArgument("input", "The input surface file");
argList::addArgument("distance"); argList::addArgument("distance", "The inflate distance");
argList::addArgument("safety factor [1..]"); argList::addArgument("factor", "The extend safety factor [1,10]");
argList::noFunctionObjects(); // Never use function objects argList::noFunctionObjects(); // Never use function objects

View File

@ -140,11 +140,12 @@ int main(int argc, char *argv[])
argList::noParallel(); argList::noParallel();
argList::validOptions.clear(); argList::validOptions.clear();
argList::addArgument("surfaceFile"); argList::addArgument("input", "The input surface file");
argList::addArgument("lambda (0..1)"); argList::addArgument("lambda", "On the interval [0,1]");
argList::addArgument("mu (0..1)"); argList::addArgument("mu", "On the interval [0,1]");
argList::addArgument("iterations"); argList::addArgument("iterations", "The number of iterations to perform");
argList::addArgument("output surfaceFile"); argList::addArgument("output", "The output surface file");
argList::addOption argList::addOption
( (
"featureFile", "featureFile",

View File

@ -80,8 +80,8 @@ int main(int argc, char *argv[])
); );
argList::noParallel(); argList::noParallel();
argList::addArgument("inputFile"); argList::addArgument("input", "The input surface file");
argList::addArgument("outputFile"); argList::addArgument("output", "The output surface file");
argList::addBoolOption argList::addBoolOption
( (

View File

@ -81,7 +81,7 @@ int main(int argc, char *argv[])
); );
argList::noParallel(); argList::noParallel();
argList::addArgument("outputFile"); argList::addArgument("output", "The output surface file");
argList::addBoolOption argList::addBoolOption
( (

View File

@ -81,7 +81,7 @@ int main(int argc, char *argv[])
); );
argList::noParallel(); argList::noParallel();
argList::addArgument("inputFile"); argList::addArgument("surface", "The input surface file");
argList::addBoolOption argList::addBoolOption
( (

View File

@ -81,7 +81,7 @@ int main(int argc, char *argv[])
argList::noBanner(); argList::noBanner();
argList::noParallel(); argList::noParallel();
argList::addArgument("surfaceFile"); argList::addArgument("surface", "The input surface file");
argList::addOption argList::addOption
( (

View File

@ -66,7 +66,8 @@ int main(int argc, char *argv[])
); );
timeSelector::addOptions(); timeSelector::addOptions();
argList::addArgument("output file"); argList::addArgument("output", "The output surface file");
#include "addRegionOption.H" #include "addRegionOption.H"
argList::addBoolOption argList::addBoolOption
( (

View File

@ -50,9 +50,10 @@ int main(int argc, char *argv[])
); );
argList::noParallel(); argList::noParallel();
argList::addArgument("surfaceFile"); argList::addArgument("input", "The input surface file");
argList::addArgument("visiblePoint"); argList::addArgument("point", "The visible 'outside' point");
argList::addArgument("output surfaceFile"); argList::addArgument("output", "The output surface file");
argList::addBoolOption argList::addBoolOption
( (
"inside", "inside",

View File

@ -51,9 +51,9 @@ int main(int argc, char *argv[])
"Merge points on surface if they are within absolute distance [m]." "Merge points on surface if they are within absolute distance [m]."
); );
argList::noParallel(); argList::noParallel();
argList::addArgument("surfaceFile"); argList::addArgument("input", "The input surface file");
argList::addArgument("merge distance"); argList::addArgument("distance", "The merge distance");
argList::addArgument("output surfaceFile"); argList::addArgument("output", "The output surface file");
argList::addOption argList::addOption
( (

View File

@ -59,8 +59,8 @@ int main(int argc, char *argv[])
"Refine by splitting all three edges of triangle" "Refine by splitting all three edges of triangle"
); );
argList::noParallel(); argList::noParallel();
argList::addArgument("surfaceFile"); argList::addArgument("input", "The input surface file");
argList::addArgument("output surfaceFile"); argList::addArgument("output", "The output surface file");
argList args(argc, argv); argList args(argc, argv);
const fileName surfFileName = args[1]; const fileName surfFileName = args[1];

View File

@ -47,7 +47,7 @@ int main(int argc, char *argv[])
); );
argList::noParallel(); argList::noParallel();
argList::addArgument("input surfaceFile"); argList::addArgument("input", "The input surface file");
argList args(argc, argv); argList args(argc, argv);
const fileName surfName = args[1]; const fileName surfName = args[1];

View File

@ -53,8 +53,8 @@ int main(int argc, char *argv[])
argList::noParallel(); argList::noParallel();
argList::validOptions.clear(); argList::validOptions.clear();
argList::addArgument("input surface file"); argList::addArgument("input", "The input surface file");
argList::addArgument("output surface file"); argList::addArgument("output", "The output surface file");
argList args(argc, argv); argList args(argc, argv);
fileName surfFileName(args[1]); fileName surfFileName(args[1]);

View File

@ -681,8 +681,8 @@ int main(int argc, char *argv[])
"Split multiply connected surface edges by duplicating points" "Split multiply connected surface edges by duplicating points"
); );
argList::noParallel(); argList::noParallel();
argList::addArgument("surfaceFile"); argList::addArgument("input", "The input surface file");
argList::addArgument("output surfaceFile"); argList::addArgument("output", "The output surface file");
argList::addBoolOption argList::addBoolOption
( (
"debug", "debug",

View File

@ -58,9 +58,9 @@ int main(int argc, char *argv[])
); );
argList::noParallel(); argList::noParallel();
argList::addArgument("surfaceSubsetDict"); argList::addArgument("dict", "The surfaceSubsetDict");
argList::addArgument("surfaceFile"); argList::addArgument("input", "The input surface file");
argList::addArgument("output surfaceFile"); argList::addArgument("output", "The output surface file");
argList args(argc, argv); argList args(argc, argv);
Info<< "Reading dictionary " << args[1] << " ..." << endl; Info<< "Reading dictionary " << args[1] << " ..." << endl;

View File

@ -66,8 +66,8 @@ int main(int argc, char *argv[])
"Note: roll=rotate about x, pitch=rotate about y, yaw=rotate about z" "Note: roll=rotate about x, pitch=rotate about y, yaw=rotate about z"
); );
argList::noParallel(); argList::noParallel();
argList::addArgument("surfaceFile"); argList::addArgument("input", "The input surface file");
argList::addArgument("output surfaceFile"); argList::addArgument("output", "The output surface file");
argList::addOption argList::addOption
( (
"translate", "translate",

View File

@ -55,6 +55,8 @@ Foam::SLList<Foam::string> Foam::argList::validArgs;
Foam::HashSet<Foam::string> Foam::argList::advancedOptions; 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::label, Foam::Hash<Foam::label>>
Foam::argList::argUsage;
Foam::HashTable<Foam::string> Foam::argList::optionUsage; Foam::HashTable<Foam::string> Foam::argList::optionUsage;
Foam::HashTable<std::pair<Foam::word,int>> Foam::argList::validOptionsCompat; Foam::HashTable<std::pair<Foam::word,int>> Foam::argList::validOptionsCompat;
Foam::HashTable<std::pair<bool,int>> Foam::argList::ignoreOptionsCompat; Foam::HashTable<std::pair<bool,int>> Foam::argList::ignoreOptionsCompat;
@ -68,32 +70,44 @@ Foam::argList::initValidTables::initValidTables()
{ {
argList::addOption argList::addOption
( (
"case", "dir", "case",
"dir",
"Specify case directory to use (instead of the cwd)" "Specify case directory to use (instead of the cwd)"
); );
argList::addBoolOption("parallel", "Run in parallel"); argList::addBoolOption("parallel", "Run in parallel");
validParOptions.set("parallel", ""); validParOptions.set("parallel", "");
argList::addOption argList::addOption
( (
"roots", "(dir1 .. dirN)", "roots",
"(dir1 .. dirN)",
"Slave root directories for distributed running", "Slave root directories for distributed running",
true // advanced option true // advanced option
); );
validParOptions.set("roots", "(dir1 .. dirN)"); validParOptions.set
(
"roots",
"(dir1 .. dirN)"
);
argList::addOption argList::addOption
( (
"decomposeParDict", "file", "decomposeParDict",
"file",
"Use specified file for decomposePar dictionary" "Use specified file for decomposePar dictionary"
); );
argList::addOption argList::addOption
( (
"hostRoots", "(((host1 dir1) .. (hostN dirN))", "hostRoots",
"(((host1 dir1) .. (hostN dirN))",
"slave root directories (per host) for distributed running. " "slave root directories (per host) for distributed running. "
"The host specification can use a regex.", "The host specification can use a regex.",
true // advanced option true // advanced option
); );
validParOptions.set("hostRoots", "((host1 dir1) .. (hostN dirN))"); validParOptions.set
(
"hostRoots",
"((host1 dir1) .. (hostN dirN))"
);
argList::addBoolOption argList::addBoolOption
( (
@ -103,7 +117,8 @@ Foam::argList::initValidTables::initValidTables()
argList::addOption argList::addOption
( (
"fileHandler", "handler", "fileHandler",
"handler",
"Override the file handler type", "Override the file handler type",
true // advanced option true // advanced option
); );
@ -229,9 +244,26 @@ void Foam::argList::checkITstream(const ITstream& is, const word& optName)
} }
void Foam::argList::addArgument(const string& argName) void Foam::argList::addArgument
(
const string& argName,
const string& usage
)
{ {
validArgs.append(argName); validArgs.append(argName);
// The first program argument starts at 1 - obtain index after the append
const label index = validArgs.size();
if (usage.empty())
{
argUsage.erase(index);
}
else
{
argUsage.set(index, usage);
}
} }

View File

@ -212,16 +212,19 @@ public:
// Stored as (option = bool, version) // Stored as (option = bool, version)
static HashTable<std::pair<bool,int>> ignoreOptionsCompat; static HashTable<std::pair<bool,int>> ignoreOptionsCompat;
//- Short usage information for validOptions //- Short description for program arguments
static HashTable<string, label, Hash<label>> argUsage;
//- Short description for validOptions
static HashTable<string> optionUsage; static HashTable<string> optionUsage;
//- Additional notes for usage //- General usage notes
static SLList<string> notes; static SLList<string> notes;
//- Min offset for displaying usage (default: 20) //- Min indentation when displaying usage (default: 20)
static std::string::size_type usageMin; static std::string::size_type usageMin;
//- Max screen width for displaying usage (default: 80) //- Max screen width when displaying usage (default: 80)
static std::string::size_type usageMax; static std::string::size_type usageMax;
//- Standard name for the post-processing option //- Standard name for the post-processing option
@ -341,11 +344,16 @@ public:
//- Return an input stream from the named option //- Return an input stream from the named option
inline ITstream lookup(const word& optName) const; inline ITstream lookup(const word& optName) const;
//- Read a value from the named option //- Get a value from the named option
// The default template parameter is string (ie, no conversion). // The default template parameter is string (ie, no conversion).
template<class T=string> template<class T=string>
inline T opt(const word& optName) const; inline T opt(const word& optName) const;
//- Get a value from the named option if present, or return default.
// Identical to lookupOrDefault().
template<class T>
inline T opt(const word& optName, const T& deflt) const;
//- Read a value from the named option if present. //- Read a value from the named option if present.
// \return true if the named option was found. // \return true if the named option was found.
template<class T> template<class T>
@ -362,8 +370,7 @@ public:
const T& deflt const T& deflt
) const; ) const;
//- Read a value from the named option if present. //- Get a value from the named option if present, or return default.
// Return supplied default otherwise.
template<class T> template<class T>
inline T lookupOrDefault inline T lookupOrDefault
( (
@ -389,7 +396,11 @@ public:
// Edit // Edit
//- Append a (mandatory) argument to validArgs //- Append a (mandatory) argument to validArgs
static void addArgument(const string& argName); static void addArgument
(
const string& argName,
const string& usage = ""
);
//- Add a bool option to validOptions with usage information //- Add a bool option to validOptions with usage information
static void addBoolOption static void addBoolOption

View File

@ -240,6 +240,35 @@ void Foam::argList::printMan() const
} }
// Arguments output
if (validArgs.size())
{
// .SH "ARGUMENTS"
Info<< ".SH \"ARGUMENTS\"" << nl;
label argIndex = 0;
for (const std::string& argName : validArgs)
{
++argIndex;
Info<< ".TP\n\\fI" << argName.c_str() << "\\fR";
Info<< nl;
// Arg has usage information?
const auto usageIter = argList::argUsage.cfind(argIndex);
if (usageIter.found())
{
stringOps::writeWrapped(Info, *usageIter, usageMax, 0, true);
}
else
{
Info<< nl;
}
}
}
// .SH "OPTIONS" // .SH "OPTIONS"
Info<< ".SH \"OPTIONS\"" << nl; Info<< ".SH \"OPTIONS\"" << nl;
@ -320,6 +349,34 @@ void Foam::argList::printUsage(bool full) const
} }
Info<< nl; Info<< nl;
// Arguments output
// Currently only if there is also usage information, but may wish to
// change this to remind developers to add some description.
if (validArgs.size() && argUsage.size())
{
Info<< "Arguments:\n";
label argIndex = 0;
for (const std::string& argName : validArgs)
{
++argIndex;
Info<< " <" << argName.c_str() << '>';
const auto usageIter = argList::argUsage.cfind(argIndex);
if (usageIter.found())
{
const label len = argName.size() + 4;
printOptionUsage(len, usageIter());
}
else
{
Info<< nl;
}
}
}
Info<< "Options:\n"; Info<< "Options:\n";
for (const word& optName : validOptions.sortedToc()) for (const word& optName : validOptions.sortedToc())

View File

@ -256,6 +256,18 @@ inline T Foam::argList::opt(const word& optName) const
} }
template<class T>
inline T Foam::argList::opt(const word& optName, const T& deflt) const
{
if (found(optName))
{
return opt<T>(optName);
}
return deflt;
}
template<class T> template<class T>
inline bool Foam::argList::readIfPresent inline bool Foam::argList::readIfPresent
( (