190 {}
191 ) {
192 std::set<std::string, std::less<>> allowed_values;
193 std::set<std::string, std::less<>> allowed_flags;
194 for (const auto value : allowed) {
195 allowed_values.emplace(value);
196 }
197 for (const auto value : flags) {
198 allowed_flags.emplace(value);
199 }
200 for (std::size_t index = first; index < arguments.size();) {
201 const std::string& name = arguments[index];
202 if (!name.starts_with("--")) {
203 throw cli_error("unexpected positional argument: " + name);
204 }
206 throw cli_error("duplicate option: " + name);
207 }
208 if (allowed_flags.contains(name)) {
210 ++index;
211 continue;
212 }
213 if (!allowed_values.contains(name)) {
214 throw cli_error("unknown option: " + name);
215 }
216 if (index + 1U >= arguments.size()
217 || arguments[index + 1U].starts_with("--")) {
218 throw cli_error("option requires a value: " + name);
219 }
220 values_.emplace(name, arguments[index + 1U]);
221 index += 2U;
222 }
223 }