Parse args
This commit is contained in:
22
options.cpp
22
options.cpp
@@ -55,6 +55,28 @@ void OptionsBase::read(const std::string& filename) {
|
||||
kv[key] = value;
|
||||
}
|
||||
|
||||
for (auto* opt : getOptions()) {
|
||||
if (kv.count(opt->key)) {
|
||||
opt->setFromString(kv[opt->key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OptionsBase::parse(const int argc, const char ** argv) {
|
||||
std::unordered_map<std::string, std::string> kv;
|
||||
|
||||
std::string key, value, line;
|
||||
|
||||
for(int i = 0; i < argc; i++) {
|
||||
line = std::string(argv[i]);
|
||||
if (line.size() < 1 || line[0] == '#') continue; // skip comment lines TODO make better
|
||||
auto pos = line.find('=');
|
||||
if (pos == std::string::npos) continue; // skip invalid lines
|
||||
std::string key = line.substr(0, pos);
|
||||
std::string value = line.substr(pos + 1);
|
||||
kv[key] = value;
|
||||
}
|
||||
|
||||
for (auto* opt : getOptions()) {
|
||||
if (kv.count(opt->key)) {
|
||||
opt->setFromString(kv[opt->key]);
|
||||
|
||||
Reference in New Issue
Block a user