Merge pull request #82 from JadeMatrix/chainable

Make ArgumentParser::add_*() functions working on the parser itself chainable
This commit is contained in:
Pranav 2020-08-22 15:42:25 -05:00 committed by GitHub
commit 0402f2b7c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -798,7 +798,8 @@ public:
// Parameter packed add_parents method // Parameter packed add_parents method
// Accepts a variadic number of ArgumentParser objects // Accepts a variadic number of ArgumentParser objects
template <typename... Targs> void add_parents(const Targs &... Fargs) { template <typename... Targs>
ArgumentParser &add_parents(const Targs &... Fargs) {
for (const ArgumentParser &tParentParser : {std::ref(Fargs)...}) { for (const ArgumentParser &tParentParser : {std::ref(Fargs)...}) {
for (auto &tArgument : tParentParser.mPositionalArguments) { for (auto &tArgument : tParentParser.mPositionalArguments) {
auto it = auto it =
@ -811,14 +812,17 @@ public:
index_argument(it); index_argument(it);
} }
} }
return *this;
} }
void add_description(std::string aDescription) { ArgumentParser &add_description(std::string aDescription) {
mDescription = std::move(aDescription); mDescription = std::move(aDescription);
return *this;
} }
void add_epilog(std::string aEpilog) { ArgumentParser &add_epilog(std::string aEpilog) {
mEpilog = std::move(aEpilog); mEpilog = std::move(aEpilog);
return *this;
} }
/* Call parse_args_internal - which does all the work /* Call parse_args_internal - which does all the work