Parameters::printUsage: drop default parameter for stream

This commit is contained in:
Arne Morten Kvarving 2024-09-04 19:43:04 +02:00
parent 4507501622
commit ed0c480a19
4 changed files with 25 additions and 19 deletions

View File

@ -556,8 +556,8 @@ void getLists(std::vector<Parameter>& 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;
}

View File

@ -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.

View File

@ -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<Parameters::EndTime<Scalar>>();
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<Parameters::InitialTimeStepSize<Scalar>>();
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;
}

View File

@ -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: