| 487 | } |
| 488 | |
| 489 | static PatternList parse_argv(Tokens tokens, std::vector<Option>& options, bool options_first) |
| 490 | { |
| 491 | // Parse command-line argument vector. |
| 492 | // |
| 493 | // If options_first: |
| 494 | // argv ::= [ long | shorts ]* [ argument ]* [ '--' [ argument ]* ] ; |
| 495 | // else: |
| 496 | // argv ::= [ long | shorts | argument ]* [ '--' [ argument ]* ] ; |
| 497 | |
| 498 | PatternList ret; |
| 499 | while (tokens) { |
| 500 | auto const& token = tokens.current(); |
| 501 | |
| 502 | if (token=="--") { |
| 503 | // option list is done; convert all the rest to arguments |
| 504 | while (tokens) { |
| 505 | ret.emplace_back(std::make_shared<Argument>("", tokens.pop())); |
| 506 | } |
| 507 | } else if (starts_with(token, "--")) { |
| 508 | auto&& parsed = parse_long(tokens, options); |
| 509 | std::move(parsed.begin(), parsed.end(), std::back_inserter(ret)); |
| 510 | } else if (token[0]=='-' && token != "-") { |
| 511 | auto&& parsed = parse_short(tokens, options); |
| 512 | std::move(parsed.begin(), parsed.end(), std::back_inserter(ret)); |
| 513 | } else if (options_first) { |
| 514 | // option list is done; convert all the rest to arguments |
| 515 | while (tokens) { |
| 516 | ret.emplace_back(std::make_shared<Argument>("", tokens.pop())); |
| 517 | } |
| 518 | } else { |
| 519 | ret.emplace_back(std::make_shared<Argument>("", tokens.pop())); |
| 520 | } |
| 521 | } |
| 522 | |
| 523 | return ret; |
| 524 | } |
| 525 | |
| 526 | std::vector<Option> parse_defaults(std::string const& doc) { |
| 527 | // This pattern is a delimiter by which we split the options. |
no test coverage detected