Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the option to add text before and after help output #72

Merged
merged 3 commits into from
Jan 3, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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