2017-04-09 02:24:32 +00:00
|
|
|
#include "options.h"
|
|
|
|
|
2017-12-02 01:04:39 +00:00
|
|
|
#include <loguru.hpp>
|
|
|
|
|
2017-04-09 02:24:32 +00:00
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
std::unordered_map<std::string, std::string> ParseOptions(int argc,
|
2017-09-22 01:14:57 +00:00
|
|
|
char** argv) {
|
2017-04-09 02:24:32 +00:00
|
|
|
std::unordered_map<std::string, std::string> output;
|
|
|
|
|
|
|
|
for (int i = 1; i < argc; ++i) {
|
|
|
|
std::string arg = argv[i];
|
2017-12-29 22:00:02 +00:00
|
|
|
if (arg[0] == '-') {
|
|
|
|
auto equal = arg.find('=');
|
|
|
|
if (equal != std::string::npos) {
|
|
|
|
output[arg.substr(0, equal)] = arg.substr(equal + 1);
|
|
|
|
} else if (i + 1 < argc && argv[i + 1][0] != '-')
|
|
|
|
output[arg] = argv[++i];
|
|
|
|
else
|
|
|
|
output[arg] = "";
|
2017-04-09 02:24:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HasOption(const std::unordered_map<std::string, std::string>& options,
|
2017-09-22 01:14:57 +00:00
|
|
|
const std::string& option) {
|
2017-04-09 02:24:32 +00:00
|
|
|
return options.find(option) != options.end();
|
2017-12-29 22:00:02 +00:00
|
|
|
}
|