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 1 commit
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
20 changes: 19 additions & 1 deletion include/argparse.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,14 @@ class ArgumentParser {
}
}

void add_pre_text(std::string aPreText) {
mPreText = std::move(aPreText);
}

void add_post_text(std::string aPostText) {
mPostText = std::move(aPostText);
}

/* 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 @@ -862,7 +870,12 @@ class ArgumentParser {
for (const auto &argument : parser.mPositionalArguments) {
stream << argument.mNames.front() << " ";
}
stream << "\n\n";
stream << "\n";

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

stream << "\n";

if (!parser.mPositionalArguments.empty())
stream << "Positional arguments:\n";
Expand All @@ -880,6 +893,9 @@ class ArgumentParser {
stream.width(tLongestArgumentLength);
stream << mOptionalArgument;
}

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

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

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