| 609 | } |
| 610 | |
| 611 | DOCOPT_INLINE |
| 612 | docopt::Options |
| 613 | docopt::docopt_parse(std::string const& doc, |
| 614 | std::vector<std::string> const& argv, |
| 615 | bool help, |
| 616 | bool version, |
| 617 | bool options_first) |
| 618 | { |
| 619 | Required pattern; |
| 620 | std::vector<Option> options; |
| 621 | try { |
| 622 | std::tie(pattern, options) = create_pattern_tree(doc); |
| 623 | } catch (Tokens::OptionError const& error) { |
| 624 | throw DocoptLanguageError(error.what()); |
| 625 | } |
| 626 | |
| 627 | PatternList argv_patterns; |
| 628 | try { |
| 629 | argv_patterns = parse_argv(Tokens(argv), options, options_first); |
| 630 | } catch (Tokens::OptionError const& error) { |
| 631 | throw DocoptArgumentError(error.what()); |
| 632 | } |
| 633 | |
| 634 | extras(help, version, argv_patterns); |
| 635 | |
| 636 | std::vector<std::shared_ptr<LeafPattern>> collected; |
| 637 | bool matched = pattern.fix().match(argv_patterns, collected); |
| 638 | if (matched && argv_patterns.empty()) { |
| 639 | docopt::Options ret; |
| 640 | |
| 641 | // (a.name, a.value) for a in (pattern.flat() + collected) |
| 642 | for (auto* p : pattern.leaves()) { |
| 643 | ret[p->name()] = p->getValue(); |
| 644 | } |
| 645 | |
| 646 | for (auto const& p : collected) { |
| 647 | ret[p->name()] = p->getValue(); |
| 648 | } |
| 649 | |
| 650 | return ret; |
| 651 | } |
| 652 | |
| 653 | if (matched) { |
| 654 | std::string leftover = join(argv.begin(), argv.end(), ", "); |
| 655 | throw DocoptArgumentError("Unexpected argument: " + leftover); |
| 656 | } |
| 657 | |
| 658 | throw DocoptArgumentError("Arguments did not match expected patterns"); // BLEH. Bad error. |
| 659 | } |
| 660 | |
| 661 | DOCOPT_INLINE |
| 662 | docopt::Options |
nothing calls this directly
no test coverage detected