Skip to content

Commit

Permalink
Merge pull request #82 from JadeMatrix/chainable
Browse files Browse the repository at this point in the history
Make ArgumentParser::add_*() functions working on the parser itself chainable
  • Loading branch information
p-ranav authored Aug 22, 2020
2 parents 37264dc + aef670b commit 0402f2b
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions include/argparse/argparse.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,8 @@ class ArgumentParser {

// Parameter packed add_parents method
// 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 (auto &tArgument : tParentParser.mPositionalArguments) {
auto it =
Expand All @@ -811,14 +812,17 @@ class ArgumentParser {
index_argument(it);
}
}
return *this;
}

void add_description(std::string aDescription) {
ArgumentParser &add_description(std::string aDescription) {
mDescription = std::move(aDescription);
return *this;
}

void add_epilog(std::string aEpilog) {
ArgumentParser &add_epilog(std::string aEpilog) {
mEpilog = std::move(aEpilog);
return *this;
}

/* Call parse_args_internal - which does all the work
Expand Down

0 comments on commit 0402f2b

Please sign in to comment.