MCPcopy Create free account
hub / github.com/docopt/docopt.cpp / parse_argv

Function parse_argv

docopt.cpp:489–524  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

487}
488
489static 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
526std::vector<Option> parse_defaults(std::string const& doc) {
527 // This pattern is a delimiter by which we split the options.

Callers 1

docopt_parseMethod · 0.85

Calls 4

starts_withFunction · 0.85
parse_longFunction · 0.85
parse_shortFunction · 0.85
popMethod · 0.80

Tested by

no test coverage detected