Skip to content

Commit 0718ad7

Browse files
indianakernickjaredgrubb
authored andcommitted
Add options type-alias
1 parent c8a63d5 commit 0718ad7

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

docopt.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ static std::pair<Required, std::vector<Option>> create_pattern_tree(std::string
609609
}
610610

611611
DOCOPT_INLINE
612-
std::map<std::string, value>
612+
docopt::options
613613
docopt::docopt_parse(std::string const& doc,
614614
std::vector<std::string> const& argv,
615615
bool help,
@@ -636,7 +636,7 @@ docopt::docopt_parse(std::string const& doc,
636636
std::vector<std::shared_ptr<LeafPattern>> collected;
637637
bool matched = pattern.fix().match(argv_patterns, collected);
638638
if (matched && argv_patterns.empty()) {
639-
std::map<std::string, value> ret;
639+
options ret;
640640

641641
// (a.name, a.value) for a in (pattern.flat() + collected)
642642
for (auto* p : pattern.leaves()) {
@@ -659,7 +659,7 @@ docopt::docopt_parse(std::string const& doc,
659659
}
660660

661661
DOCOPT_INLINE
662-
std::map<std::string, value>
662+
docopt::options
663663
docopt::docopt(std::string const& doc,
664664
std::vector<std::string> const& argv,
665665
bool help,

docopt.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ namespace docopt {
5454

5555
// Arguments contained '--version' and parsing was aborted early
5656
struct DocoptExitVersion : std::runtime_error { DocoptExitVersion() : std::runtime_error("Docopt --version argument encountered") {} };
57+
58+
/// A map of options set by the user
59+
using options = std::map<std::string, value>;
5760

5861
/// Parse user options from the given option string.
5962
///
@@ -68,7 +71,7 @@ namespace docopt {
6871
/// @throws DocoptExitHelp if 'help' is true and the user has passed the '--help' argument
6972
/// @throws DocoptExitVersion if 'version' is true and the user has passed the '--version' argument
7073
/// @throws DocoptArgumentError if the user's argv did not match the usage patterns
71-
std::map<std::string, value> DOCOPT_API docopt_parse(std::string const& doc,
74+
options DOCOPT_API docopt_parse(std::string const& doc,
7275
std::vector<std::string> const& argv,
7376
bool help = true,
7477
bool version = true,
@@ -81,7 +84,7 @@ namespace docopt {
8184
/// * DocoptExitHelp - print usage string and terminate (with exit code 0)
8285
/// * DocoptExitVersion - print version and terminate (with exit code 0)
8386
/// * DocoptArgumentError - print error and usage string and terminate (with exit code -1)
84-
std::map<std::string, value> DOCOPT_API docopt(std::string const& doc,
87+
options DOCOPT_API docopt(std::string const& doc,
8588
std::vector<std::string> const& argv,
8689
bool help = true,
8790
std::string const& version = {},

0 commit comments

Comments
 (0)