ccls/src/options.cc

35 lines
848 B
C++
Raw Normal View History

2017-04-09 02:24:32 +00:00
#include "options.h"
#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;
std::string previous_arg;
for (int i = 1; i < argc; ++i) {
std::string arg = argv[i];
if (arg[0] != '-') {
if (previous_arg.size() == 0) {
std::cerr << "Invalid arguments; switches must start with -"
2017-09-22 01:14:57 +00:00
<< std::endl;
2017-04-09 02:24:32 +00:00
exit(1);
}
output[previous_arg] = arg;
previous_arg = "";
2017-09-22 01:14:57 +00:00
} else {
2017-04-09 02:24:32 +00:00
output[arg] = "";
previous_arg = arg;
}
}
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();
}