From 89b9e22f9aef6ebb7b458a1ca4acd1bb19844a6d Mon Sep 17 00:00:00 2001 From: Ethan Slattery <9755578+CrustyAuklet@users.noreply.github.com> Date: Sun, 29 Dec 2019 10:46:31 -0800 Subject: [PATCH] add pre and post text options add variables, assignment functions, and printing for text before and after the argument lists. --- include/argparse.hpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/include/argparse.hpp b/include/argparse.hpp index 109d6cb..d4f5ca4 100644 --- a/include/argparse.hpp +++ b/include/argparse.hpp @@ -800,6 +800,14 @@ public: } } + 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 @@ -862,7 +870,12 @@ public: 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"; @@ -880,6 +893,9 @@ public: stream.width(tLongestArgumentLength); stream << mOptionalArgument; } + + if(!parser.mPostText.empty()) + stream << parser.mPostText << "\n\n"; } return stream; @@ -988,6 +1004,8 @@ private: } std::string mProgramName; + std::string mPreText; + std::string mPostText; std::list mPositionalArguments; std::list mOptionalArguments; std::map> mArgumentMap;