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");
|
||||
const wordList opts(helpType::dictionaryConstructorTablePtr_->sortedToc());
|
||||
|
||||
string note = "Valid <tool> options include:";
|
||||
forAll(opts, i)
|
||||
argList::notes.append("Valid <tool> options include:");
|
||||
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 "addToolOption.H"
|
||||
|
||||
// Intercept request for help
|
||||
if ((argc > 1) && (strcmp(argv[1], "-help") == 0))
|
||||
// Intercept request for any -option (eg, -doc, -help)
|
||||
// when it is the first argument
|
||||
if (argc > 1 && '-' == *argv[1])
|
||||
{
|
||||
#include "setRootCase.H"
|
||||
}
|
||||
|
||||
if (argc < 2)
|
||||
else if (argc < 2)
|
||||
{
|
||||
FatalError
|
||||
<< "No help utility has been supplied" << nl
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
word utilityName = argv[1];
|
||||
Foam::autoPtr<Foam::helpType> utility
|
||||
(
|
||||
helpType::New(utilityName)
|
||||
);
|
||||
word utilityName(argv[1]);
|
||||
autoPtr<helpType> utility;
|
||||
|
||||
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();
|
||||
|
||||
@ -71,7 +83,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
utility().execute(args, mesh);
|
||||
|
||||
Info<< "End\n" << endl;
|
||||
Info<< "\nEnd\n" << endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -32,31 +32,35 @@ Foam::autoPtr<Foam::helpType> Foam::helpType::New
|
||||
const word& helpTypeName
|
||||
)
|
||||
{
|
||||
Info<< "Selecting helpType " << helpTypeName << endl;
|
||||
|
||||
auto cstrIter = dictionaryConstructorTablePtr_->cfind(helpTypeName);
|
||||
|
||||
if (!cstrIter.found())
|
||||
{
|
||||
// special treatment for -help
|
||||
// exit without stack trace
|
||||
if (helpTypeName == "-help")
|
||||
if (helpTypeName.startsWith("-help"))
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Valid helpType selections are:" << nl
|
||||
<< dictionaryConstructorTablePtr_->sortedToc() << nl
|
||||
<< "Valid helpType selections:" << nl
|
||||
<< " "
|
||||
<< flatOutput(dictionaryConstructorTablePtr_->sortedToc())
|
||||
<< endl
|
||||
<< exit(FatalError);
|
||||
}
|
||||
else
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Unknown helpType type " << helpTypeName << nl
|
||||
<< "Valid helpType selections are:" << nl
|
||||
<< dictionaryConstructorTablePtr_->sortedToc() << nl
|
||||
<< "Unknown helpType type '" << helpTypeName << "'" << nl << nl
|
||||
<< "Valid helpType selections:" << nl
|
||||
<< " "
|
||||
<< flatOutput(dictionaryConstructorTablePtr_->sortedToc())
|
||||
<< endl
|
||||
<< abort(FatalError);
|
||||
}
|
||||
}
|
||||
|
||||
Info<< "Selecting helpType '" << helpTypeName << "'" << endl;
|
||||
|
||||
return autoPtr<helpType>(cstrIter()());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user