diff --git a/opm/models/utils/parametersystem.cpp b/opm/models/utils/parametersystem.cpp index c3144c32c..9af377750 100644 --- a/opm/models/utils/parametersystem.cpp +++ b/opm/models/utils/parametersystem.cpp @@ -556,8 +556,8 @@ void getLists(std::vector& usedParams, } void printUsage(const std::string& helpPreamble, - const std::string& errorMsg, std::ostream& os, + const std::string& errorMsg, const bool showAll) { if (!errorMsg.empty()) { @@ -654,11 +654,11 @@ std::string parseCommandLineOptions(int argc, for (int i = 1; i < argc; ++i) { if (std::string("-h") == argv[i] || std::string("--help") == argv[i]) { - printUsage(helpPreamble, /*errorMsg=*/"", std::cout); + printUsage(helpPreamble, std::cout, /*errorMsg=*/""); return "Help called"; } if (std::string("--help-all") == argv[i]) { - printUsage(helpPreamble, /*errorMsg=*/"", std::cout, true); + printUsage(helpPreamble, std::cout, /*errorMsg=*/"", true); return "Help called"; } } @@ -682,8 +682,9 @@ std::string parseCommandLineOptions(int argc, if (numHandled < 1) { std::ostringstream oss; - if (!helpPreamble.empty()) - printUsage(helpPreamble, errorMsg, std::cerr); + if (!helpPreamble.empty()) { + printUsage(helpPreamble, std::cerr, errorMsg); + } return errorMsg; } @@ -707,8 +708,9 @@ std::string parseCommandLineOptions(int argc, << " ('" << argv[i] << "') " << "is invalid because it does not start with a letter."; - if (!helpPreamble.empty()) - printUsage(helpPreamble, oss.str(), std::cerr); + if (!helpPreamble.empty()) { + printUsage(helpPreamble, std::cerr, oss.str()); + } return oss.str(); } @@ -723,8 +725,9 @@ std::string parseCommandLineOptions(int argc, std::string("Parameter '")+paramName+"' specified multiple times as a " "command line parameter"; - if (!helpPreamble.empty()) - printUsage(helpPreamble, msg, std::cerr); + if (!helpPreamble.empty()) { + printUsage(helpPreamble, std::cerr, msg); + } return msg; } seenKeys.insert(paramName); @@ -734,8 +737,9 @@ std::string parseCommandLineOptions(int argc, std::string("Parameter '")+paramName+"' is missing a value. " +" Please use "+argv[i]+"=value."; - if (!helpPreamble.empty()) - printUsage(helpPreamble, msg, std::cerr); + if (!helpPreamble.empty()) { + printUsage(helpPreamble, std::cerr, msg); + } return msg; } diff --git a/opm/models/utils/parametersystem.hpp b/opm/models/utils/parametersystem.hpp index 4c3b618f2..7618bde67 100644 --- a/opm/models/utils/parametersystem.hpp +++ b/opm/models/utils/parametersystem.hpp @@ -127,8 +127,8 @@ int getTtyWidth(); * \param os The \c std::ostream which should be used. */ void printUsage(const std::string& helpPreamble, + std::ostream& os, const std::string& errorMsg = "", - std::ostream& os = std::cerr, const bool showAll = false); //! \brief Callback function for command line parsing. diff --git a/opm/models/utils/start.hh b/opm/models/utils/start.hh index 99a077282..0a97b32e3 100644 --- a/opm/models/utils/start.hh +++ b/opm/models/utils/start.hh @@ -161,7 +161,7 @@ static inline int setupParameters_(int argc, if (myRank == 0) { oss << "Parameter file \"" << paramFileName << "\" does not exist or is not readable."; - Parameters::printUsage(argv[0], oss.str()); + Parameters::printUsage(argv[0], std::cerr, oss.str()); } return /*status=*/1; } @@ -316,18 +316,20 @@ static inline int start(int argc, char **argv, bool registerParams=true) // read the initial time step and the end time Scalar endTime = Parameters::Get>(); if (endTime < -1e50) { - if (myRank == 0) - Parameters::printUsage(argv[0], + if (myRank == 0) { + Parameters::printUsage(argv[0], std::cerr, "Mandatory parameter '--end-time' not specified!"); + } return 1; } Scalar initialTimeStepSize = Parameters::Get>(); if (initialTimeStepSize < -1e50) { - if (myRank == 0) - Parameters::printUsage(argv[0], + if (myRank == 0) { + Parameters::printUsage(argv[0], std::cerr, "Mandatory parameter '--initial-time-step-size' " "not specified!"); + } return 1; } diff --git a/tests/test_parametersystem.cpp b/tests/test_parametersystem.cpp index ca94fecd3..68726a5cd 100644 --- a/tests/test_parametersystem.cpp +++ b/tests/test_parametersystem.cpp @@ -137,7 +137,7 @@ BOOST_FIXTURE_TEST_CASE(ParseParameterFile, Fixture) BOOST_FIXTURE_TEST_CASE(PrintUsage, Fixture) { std::stringstream usage; - Opm::Parameters::printUsage("", "", usage); + Opm::Parameters::printUsage("", usage); BOOST_CHECK_EQUAL(trimString(usage.str()), trimString(R"( Recognized options: @@ -152,7 +152,7 @@ Recognized options: BOOST_FIXTURE_TEST_CASE(PrintUsageAll, Fixture) { std::stringstream usage; - Opm::Parameters::printUsage("===foobar===", "", usage, true); + Opm::Parameters::printUsage("===foobar===", usage, "", true); BOOST_CHECK_EQUAL(trimString(usage.str()), trimString(R"(===foobar=== Recognized options: