mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-25 17:11:59 +00:00
Support equal signs in options, e.g. --log-file=a.log
This commit is contained in:
parent
43ea2fcc53
commit
720266e97a
@ -8,22 +8,16 @@ std::unordered_map<std::string, std::string> ParseOptions(int argc,
|
|||||||
char** argv) {
|
char** argv) {
|
||||||
std::unordered_map<std::string, std::string> output;
|
std::unordered_map<std::string, std::string> output;
|
||||||
|
|
||||||
std::string previous_arg;
|
|
||||||
|
|
||||||
for (int i = 1; i < argc; ++i) {
|
for (int i = 1; i < argc; ++i) {
|
||||||
std::string arg = argv[i];
|
std::string arg = argv[i];
|
||||||
|
if (arg[0] == '-') {
|
||||||
if (arg[0] != '-') {
|
auto equal = arg.find('=');
|
||||||
if (previous_arg.size() == 0) {
|
if (equal != std::string::npos) {
|
||||||
LOG_S(FATAL) << "Invalid arguments; switches must start with -";
|
output[arg.substr(0, equal)] = arg.substr(equal + 1);
|
||||||
exit(1);
|
} else if (i + 1 < argc && argv[i + 1][0] != '-')
|
||||||
}
|
output[arg] = argv[++i];
|
||||||
|
else
|
||||||
output[previous_arg] = arg;
|
output[arg] = "";
|
||||||
previous_arg = "";
|
|
||||||
} else {
|
|
||||||
output[arg] = "";
|
|
||||||
previous_arg = arg;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,4 +27,4 @@ std::unordered_map<std::string, std::string> ParseOptions(int argc,
|
|||||||
bool HasOption(const std::unordered_map<std::string, std::string>& options,
|
bool HasOption(const std::unordered_map<std::string, std::string>& options,
|
||||||
const std::string& option) {
|
const std::string& option) {
|
||||||
return options.find(option) != options.end();
|
return options.find(option) != options.end();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user