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 1/3] 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; From 7ef0de410b1499080dadc36993a0a7959f2e11b2 Mon Sep 17 00:00:00 2001 From: Ethan Slattery Date: Thu, 2 Jan 2020 15:14:20 -0800 Subject: [PATCH 2/3] Better naming: follow python naming convention. --- include/argparse.hpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/include/argparse.hpp b/include/argparse.hpp index d4f5ca4..cda3cbe 100644 --- a/include/argparse.hpp +++ b/include/argparse.hpp @@ -800,12 +800,12 @@ public: } } - void add_pre_text(std::string aPreText) { - mPreText = std::move(aPreText); + void add_description(std::string aDescription) { + mDescription = std::move(aDescription); } - void add_post_text(std::string aPostText) { - mPostText = std::move(aPostText); + void add_epilog(std::string aEpilog) { + mEpilog = std::move(aEpilog); } /* Call parse_args_internal - which does all the work @@ -872,8 +872,8 @@ public: } stream << "\n"; - if(!parser.mPreText.empty()) - stream << parser.mPreText << "\n"; + if(!parser.mDescription.empty()) + stream << parser.mDescription << "\n"; stream << "\n"; @@ -894,8 +894,8 @@ public: stream << mOptionalArgument; } - if(!parser.mPostText.empty()) - stream << parser.mPostText << "\n\n"; + if(!parser.mEpilog.empty()) + stream << parser.mEpilog << "\n\n"; } return stream; @@ -1004,8 +1004,8 @@ private: } std::string mProgramName; - std::string mPreText; - std::string mPostText; + std::string mDescription; + std::string mEpilog; std::list mPositionalArguments; std::list mOptionalArguments; std::map> mArgumentMap; From c521ebeaf88e9b641d8cb8a7e753d593d735d510 Mon Sep 17 00:00:00 2001 From: Ethan Slattery Date: Thu, 2 Jan 2020 18:42:25 -0800 Subject: [PATCH 3/3] add extra space to match python formatting --- include/argparse.hpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/include/argparse.hpp b/include/argparse.hpp index cda3cbe..ae67ab0 100644 --- a/include/argparse.hpp +++ b/include/argparse.hpp @@ -870,12 +870,10 @@ public: for (const auto &argument : parser.mPositionalArguments) { stream << argument.mNames.front() << " "; } - stream << "\n"; + stream << "\n\n"; if(!parser.mDescription.empty()) - stream << parser.mDescription << "\n"; - - stream << "\n"; + stream << parser.mDescription << "\n\n"; if (!parser.mPositionalArguments.empty()) stream << "Positional arguments:\n";