37 CommandLinePropertySource::CommandLinePropertySource(
int argc,
39 bool reportSyntaxErrors,
41 logger(logging::Logger::
getLogger(
"rsc.config.CommandLineSource")),
42 argc(argc), argv(argv),
43 reportSyntaxErrors(reportSyntaxErrors), option(option) {
51 for (
int i = 1; i <
argc; ++i) {
53 string rawOption =
argv[i];
57 if (rawOption.size() < 2) {
58 RSCTRACE(
logger,
"Ignoring uninteresting option '" << rawOption <<
"'");
64 if (rawOption ==
"--") {
69 if (rawOption.substr(0, 2) != string(
"-") +
option) {
70 RSCTRACE(
logger,
"Ignoring uninteresting option '" << rawOption <<
"'");
76 if (rawOption.length() == 2 && i < argc - 1) {
80 rawOption = rawOption.substr(2, rawOption.length() - 2);
83 size_t equalsPos = rawOption.find_first_of(
'=');
84 if (equalsPos == string::npos) {
86 "Cannot parse option '" << rawOption <<
"'. Reason: = character missing");
88 throw invalid_argument(
89 "Cannot parse option '" + rawOption
90 +
"'. Reason: = character missing");
96 string rawKey = rawOption.substr(0, equalsPos);
97 string value = rawOption.substr(equalsPos + 1,
98 rawOption.length() - equalsPos - 1);
101 "Parsed rawKey = '" << rawKey <<
"', value = '" << value <<
"'");
110 }
catch (invalid_argument& e) {
virtual void handleOption(const std::vector< std::string > &key, const std::string &value)=0
This method is called once for each individual option available from a given ConfigSource.
void splitKeyAtDots(const std::string &input, std::vector< std::string > &output)
Creates a key vector structure used in the options backend from a dot-separated string.
Implementations of this interface receive options from ConfigSource objects.
virtual ~CommandLinePropertySource()
#define RSCWARN(logger, msg)
#define RSCTRACE(logger, msg)
logging::LoggerPtr logger
void provideOptions(OptionHandler &handler)
Implementations should pass all configuration options to handler.