mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: improve error handling for foamHelp
- Catch any leading option (the incorrect location). - Catch initialization error for cleaner result.
This commit is contained in:
@ -1,10 +1,12 @@
|
|||||||
argList::addArgument("tool");
|
argList::addArgument("tool");
|
||||||
const wordList opts(helpType::dictionaryConstructorTablePtr_->sortedToc());
|
|
||||||
|
|
||||||
string note = "Valid <tool> options include:";
|
argList::notes.append("Valid <tool> options include:");
|
||||||
forAll(opts, i)
|
for (const word& tool : helpType::dictionaryConstructorTablePtr_->sortedToc())
|
||||||
{
|
{
|
||||||
note = note + ' ' + opts[i];
|
argList::notes.append(" " + tool);
|
||||||
}
|
}
|
||||||
|
|
||||||
argList::notes.append(note);
|
argList::notes.append
|
||||||
|
(
|
||||||
|
"\nNOTE the <tool> must actually appear *before* any options"
|
||||||
|
);
|
||||||
|
|||||||
@ -44,24 +44,36 @@ int main(int argc, char *argv[])
|
|||||||
#include "addRegionOption.H"
|
#include "addRegionOption.H"
|
||||||
#include "addToolOption.H"
|
#include "addToolOption.H"
|
||||||
|
|
||||||
// Intercept request for help
|
// Intercept request for any -option (eg, -doc, -help)
|
||||||
if ((argc > 1) && (strcmp(argv[1], "-help") == 0))
|
// when it is the first argument
|
||||||
|
if (argc > 1 && '-' == *argv[1])
|
||||||
{
|
{
|
||||||
#include "setRootCase.H"
|
#include "setRootCase.H"
|
||||||
}
|
}
|
||||||
|
else if (argc < 2)
|
||||||
if (argc < 2)
|
|
||||||
{
|
{
|
||||||
FatalError
|
FatalError
|
||||||
<< "No help utility has been supplied" << nl
|
<< "No help utility has been supplied" << nl
|
||||||
<< exit(FatalError);
|
<< exit(FatalError);
|
||||||
}
|
}
|
||||||
|
|
||||||
word utilityName = argv[1];
|
word utilityName(argv[1]);
|
||||||
Foam::autoPtr<Foam::helpType> utility
|
autoPtr<helpType> utility;
|
||||||
(
|
|
||||||
helpType::New(utilityName)
|
const bool throwing = FatalError.throwExceptions();
|
||||||
);
|
try
|
||||||
|
{
|
||||||
|
utility.reset(helpType::New(utilityName));
|
||||||
|
}
|
||||||
|
catch (Foam::error& err)
|
||||||
|
{
|
||||||
|
utility.clear();
|
||||||
|
|
||||||
|
FatalError
|
||||||
|
<< err.message().c_str() << nl
|
||||||
|
<< exit(FatalError);
|
||||||
|
}
|
||||||
|
FatalError.throwExceptions(throwing);
|
||||||
|
|
||||||
utility().init();
|
utility().init();
|
||||||
|
|
||||||
@ -71,7 +83,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
utility().execute(args, mesh);
|
utility().execute(args, mesh);
|
||||||
|
|
||||||
Info<< "End\n" << endl;
|
Info<< "\nEnd\n" << endl;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -32,31 +32,35 @@ Foam::autoPtr<Foam::helpType> Foam::helpType::New
|
|||||||
const word& helpTypeName
|
const word& helpTypeName
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
Info<< "Selecting helpType " << helpTypeName << endl;
|
|
||||||
|
|
||||||
auto cstrIter = dictionaryConstructorTablePtr_->cfind(helpTypeName);
|
auto cstrIter = dictionaryConstructorTablePtr_->cfind(helpTypeName);
|
||||||
|
|
||||||
if (!cstrIter.found())
|
if (!cstrIter.found())
|
||||||
{
|
{
|
||||||
// special treatment for -help
|
// special treatment for -help
|
||||||
// exit without stack trace
|
// exit without stack trace
|
||||||
if (helpTypeName == "-help")
|
if (helpTypeName.startsWith("-help"))
|
||||||
{
|
{
|
||||||
FatalErrorInFunction
|
FatalErrorInFunction
|
||||||
<< "Valid helpType selections are:" << nl
|
<< "Valid helpType selections:" << nl
|
||||||
<< dictionaryConstructorTablePtr_->sortedToc() << nl
|
<< " "
|
||||||
|
<< flatOutput(dictionaryConstructorTablePtr_->sortedToc())
|
||||||
|
<< endl
|
||||||
<< exit(FatalError);
|
<< exit(FatalError);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
FatalErrorInFunction
|
FatalErrorInFunction
|
||||||
<< "Unknown helpType type " << helpTypeName << nl
|
<< "Unknown helpType type '" << helpTypeName << "'" << nl << nl
|
||||||
<< "Valid helpType selections are:" << nl
|
<< "Valid helpType selections:" << nl
|
||||||
<< dictionaryConstructorTablePtr_->sortedToc() << nl
|
<< " "
|
||||||
|
<< flatOutput(dictionaryConstructorTablePtr_->sortedToc())
|
||||||
|
<< endl
|
||||||
<< abort(FatalError);
|
<< abort(FatalError);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Info<< "Selecting helpType '" << helpTypeName << "'" << endl;
|
||||||
|
|
||||||
return autoPtr<helpType>(cstrIter()());
|
return autoPtr<helpType>(cstrIter()());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user