Skip to content

Commit

Permalink
Merge pull request #72 from CrustyAuklet/text-pre-post
Browse files Browse the repository at this point in the history
Add the option to add text before and after help output
  • Loading branch information
p-ranav authored Jan 3, 2020
2 parents c13e83d + c521ebe commit f01beb8
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions include/argparse.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,14 @@ class ArgumentParser {
}
}

void add_description(std::string aDescription) {
mDescription = std::move(aDescription);
}

void add_epilog(std::string aEpilog) {
mEpilog = std::move(aEpilog);
}

/* Call parse_args_internal - which does all the work
* Then, validate the parsed arguments
* This variant is used mainly for testing
Expand Down Expand Up @@ -864,6 +872,9 @@ class ArgumentParser {
}
stream << "\n\n";

if(!parser.mDescription.empty())
stream << parser.mDescription << "\n\n";

if (!parser.mPositionalArguments.empty())
stream << "Positional arguments:\n";

Expand All @@ -880,6 +891,9 @@ class ArgumentParser {
stream.width(tLongestArgumentLength);
stream << mOptionalArgument;
}

if(!parser.mEpilog.empty())
stream << parser.mEpilog << "\n\n";
}

return stream;
Expand Down Expand Up @@ -988,6 +1002,8 @@ class ArgumentParser {
}

std::string mProgramName;
std::string mDescription;
std::string mEpilog;
std::list<Argument> mPositionalArguments;
std::list<Argument> mOptionalArguments;
std::map<std::string_view, list_iterator, std::less<>> mArgumentMap;
Expand Down

0 comments on commit f01beb8

Please sign in to comment.