| 111 | } |
| 112 | |
| 113 | bool HandleGetCommand(std::vector<std::string> const& args, |
| 114 | cmExecutionStatus& status) |
| 115 | { |
| 116 | if (args.size() < 4) { |
| 117 | status.SetError("sub-command GET requires at least three arguments."); |
| 118 | return false; |
| 119 | } |
| 120 | |
| 121 | std::string const& listName = args[1]; |
| 122 | std::string const& variableName = args.back(); |
| 123 | // expand the variable |
| 124 | auto list = GetList(listName, status.GetMakefile()); |
| 125 | if (!list) { |
| 126 | status.GetMakefile().AddDefinition(variableName, "NOTFOUND"); |
| 127 | return true; |
| 128 | } |
| 129 | // FIXME: Add policy to make non-existing lists an error like empty lists. |
| 130 | if (list->empty()) { |
| 131 | status.SetError("GET given empty list"); |
| 132 | return false; |
| 133 | } |
| 134 | |
| 135 | std::vector<int> indexes; |
| 136 | for (std::size_t cc = 2; cc < args.size() - 1; cc++) { |
| 137 | int index; |
| 138 | if (!GetIndexArg(args[cc], &index, status.GetMakefile())) { |
| 139 | status.SetError(cmStrCat("index: ", args[cc], " is not a valid index")); |
| 140 | return false; |
| 141 | } |
| 142 | indexes.push_back(index); |
| 143 | } |
| 144 | |
| 145 | try { |
| 146 | auto values = list->get_items(indexes.begin(), indexes.end()); |
| 147 | status.GetMakefile().AddDefinition(variableName, values.to_string()); |
| 148 | return true; |
| 149 | } catch (std::out_of_range& e) { |
| 150 | status.SetError(e.what()); |
| 151 | return false; |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | bool HandleAppendCommand(std::vector<std::string> const& args, |
| 156 | cmExecutionStatus& status) |
nothing calls this directly
no test coverage detected
searching dependent graphs…