| 48 | } |
| 49 | |
| 50 | std::vector<std::string> FlagGroup::parseFlagsWithFilenames(int argc, |
| 51 | const char* argv[], |
| 52 | std::function<bool(const std::string&)> callback) |
| 53 | { |
| 54 | if (_initialised) |
| 55 | throw std::runtime_error("called parseFlags() twice"); |
| 56 | |
| 57 | /* Recursively accumulate a list of all flags. */ |
| 58 | |
| 59 | all_flags.clear(); |
| 60 | flags_by_name.clear(); |
| 61 | std::function<void(FlagGroup*)> recurse; |
| 62 | recurse = [&](FlagGroup* group) |
| 63 | { |
| 64 | if (group->_initialised) |
| 65 | return; |
| 66 | |
| 67 | for (FlagGroup* subgroup : group->_groups) |
| 68 | recurse(subgroup); |
| 69 | |
| 70 | for (Flag* flag : group->_flags) |
| 71 | { |
| 72 | for (const auto& name : flag->names()) |
| 73 | { |
| 74 | if (flags_by_name.find(name) != flags_by_name.end()) |
| 75 | error("two flags use the name '{}'", name); |
| 76 | flags_by_name[name] = flag; |
| 77 | } |
| 78 | |
| 79 | all_flags.push_back(flag); |
| 80 | } |
| 81 | |
| 82 | group->_initialised = true; |
| 83 | }; |
| 84 | recurse(this); |
| 85 | recurse(&helpGroup); |
| 86 | |
| 87 | /* Now actually parse them. */ |
| 88 | |
| 89 | std::vector<std::string> filenames; |
| 90 | int index = 1; |
| 91 | while (index < argc) |
| 92 | { |
| 93 | std::string thisarg = argv[index]; |
| 94 | std::string thatarg = (index < (argc - 1)) ? argv[index + 1] : ""; |
| 95 | |
| 96 | std::string key; |
| 97 | std::string value; |
| 98 | bool usesthat = false; |
| 99 | |
| 100 | if (thisarg.size() == 0) |
| 101 | { |
| 102 | /* Ignore this argument. */ |
| 103 | } |
| 104 | else if (thisarg[0] != '-') |
| 105 | { |
| 106 | /* This is a filename. Pass it to the callback, and if not consumed |
| 107 | * queue it. */ |
nothing calls this directly
no test coverage detected