diff --git a/applications/utilities/miscellaneous/foamHelp/addToolOption.H b/applications/utilities/miscellaneous/foamHelp/addToolOption.H index e27745b339f8c9569e0a93003bd92ee06a636dc0..8abb062b00b41e6e7e6da9b4bf04e034d94d8566 100644 --- a/applications/utilities/miscellaneous/foamHelp/addToolOption.H +++ b/applications/utilities/miscellaneous/foamHelp/addToolOption.H @@ -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" +); diff --git a/applications/utilities/miscellaneous/foamHelp/foamHelp.C b/applications/utilities/miscellaneous/foamHelp/foamHelp.C index 88aac628c00277acfeaabf5e5879ac80877c5f9f..d99f1f6de5df14d5f381b91a0e12c9bd2450c408 100644 --- a/applications/utilities/miscellaneous/foamHelp/foamHelp.C +++ b/applications/utilities/miscellaneous/foamHelp/foamHelp.C @@ -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; } diff --git a/applications/utilities/miscellaneous/foamHelp/helpTypes/helpType/helpTypeNew.C b/applications/utilities/miscellaneous/foamHelp/helpTypes/helpType/helpTypeNew.C index dff74bf277e60611ef10ea0f002c3d30a0490962..27fcd6ea3710683e0982d5f0ea018715c598706d 100644 --- a/applications/utilities/miscellaneous/foamHelp/helpTypes/helpType/helpTypeNew.C +++ b/applications/utilities/miscellaneous/foamHelp/helpTypes/helpType/helpTypeNew.C @@ -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()()); }