Modified behaviour for unhandled arguments.
Use constructor argument verify_syntax to decide course of action: if false, store unhandled arguments, if true, write a message and throw.
This commit is contained in:
committed by
Arne Morten Kvarving
parent
9d6489f68d
commit
3dd2d565fc
@@ -127,12 +127,16 @@ namespace Opm {
|
||||
///
|
||||
/// It is required that argv[0] is the program name, while if
|
||||
/// 0 < i < argc, then argv[i] is either
|
||||
/// the name of an xml file or parametername=value.
|
||||
/// the name of an xml file, parameter file or parametername=value.
|
||||
///
|
||||
/// \param argc is the number of command-line arguments,
|
||||
/// including the name of the executable.
|
||||
/// \param argv is an array of char*, each of which is a
|
||||
/// command line argument.
|
||||
/// command line argument.
|
||||
/// \param verify_syntax If true (default), then it is an error to
|
||||
/// pass arguments that cannot be handled by the ParameterGroup,
|
||||
/// or an empty argument list. If false, such arguments are stored
|
||||
/// and can be retrieved later with unhandledArguments().
|
||||
template <typename StringArray>
|
||||
ParameterGroup(int argc, StringArray argv, const bool verify_syntax = true);
|
||||
|
||||
@@ -284,7 +288,7 @@ namespace Opm {
|
||||
template<typename T, class Requirement>
|
||||
T translate(const pair_type& data, const Requirement& chk) const;
|
||||
template <typename StringArray>
|
||||
void parseCommandLineArguments(int argc, StringArray argv);
|
||||
void parseCommandLineArguments(int argc, StringArray argv, bool verify_syntax);
|
||||
void recursiveSetIsOutputEnabled(bool output_is_enabled);
|
||||
|
||||
// helper routines to do textual I/O
|
||||
|
||||
@@ -38,11 +38,13 @@
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <stdexcept>
|
||||
|
||||
#include <opm/core/utility/parameters/ParameterGroup.hpp>
|
||||
#include <opm/core/utility/parameters/ParameterStrings.hpp>
|
||||
#include <opm/core/utility/parameters/ParameterTools.hpp>
|
||||
#include <opm/core/utility/parameters/Parameter.hpp>
|
||||
#include <opm/core/utility/ErrorMacros.hpp>
|
||||
|
||||
namespace Opm {
|
||||
namespace parameter {
|
||||
@@ -115,11 +117,11 @@ namespace Opm {
|
||||
<< "[...]" << std::endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
this->parseCommandLineArguments(argc, argv);
|
||||
this->parseCommandLineArguments(argc, argv, verify_syntax);
|
||||
}
|
||||
|
||||
template <typename StringArray>
|
||||
void ParameterGroup::parseCommandLineArguments(int argc, StringArray argv)
|
||||
void ParameterGroup::parseCommandLineArguments(int argc, StringArray argv, bool verify_syntax)
|
||||
{
|
||||
std::vector<std::string> files;
|
||||
std::vector<std::pair<std::string, std::string> > assignments;
|
||||
@@ -150,7 +152,13 @@ namespace Opm {
|
||||
} else if (file_type.second == "param") {
|
||||
this->readParam(files[i]);
|
||||
} else {
|
||||
unhandled_arguments_.push_back(files[i]);
|
||||
if (verify_syntax) {
|
||||
std::cerr << "ERROR: Input '" << files[i] << "' is not a valid name for a parameter file.\n";
|
||||
std::cerr << " Valid filename extensions are 'xml' and 'param'.\n";
|
||||
OPM_THROW(std::runtime_error, "ParameterGroup cannot handle argument: " << files[i]);
|
||||
} else {
|
||||
unhandled_arguments_.push_back(files[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < int(assignments.size()); ++i) {
|
||||
|
||||
Reference in New Issue
Block a user