From 3aef6c345b3704b94978a45f266e11abbec149f4 Mon Sep 17 00:00:00 2001 From: Kevin Lussier Date: Wed, 13 Jun 2018 18:40:10 -0700 Subject: [PATCH] Add group 'notes'. notes allow for more detailed information to be displayed at the end of the help message. --- include/cxxopts.hpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/include/cxxopts.hpp b/include/cxxopts.hpp index f590587..0f9aa02 100644 --- a/include/cxxopts.hpp +++ b/include/cxxopts.hpp @@ -997,6 +997,7 @@ namespace cxxopts std::string name; std::string description; std::vector options; + std::list notes; }; class OptionValue @@ -1240,6 +1241,9 @@ namespace cxxopts std::string arg_help ); + inline + void + add_group_note(const std::string& group, const std::string& note); //parse positional arguments into the given option void parse_positional(std::string option); @@ -1870,6 +1874,19 @@ Options::add_one_option } } +inline +void +Options::add_group_note +( + const std::string& group, + const std::string& note +) +{ + //add the help details + auto& options = m_help[group]; + options.notes.push_back(note); +} + inline String Options::help_one_group(const std::string& g) const @@ -1942,6 +1959,21 @@ Options::help_one_group(const std::string& g) const ++fiter; } + if ( !group->second.notes.empty() ) + { + auto allowed = size_t{76} - OPTION_DESC_GAP; + result += '\n'; + for ( auto note : group->second.notes ) + { + HelpOptionDetails o { "", "", note, false, "", false, "", "", false, false }; + for ( int idx = 0; idx < OPTION_DESC_GAP; idx++ ) + result += ' '; + result += "* "; + result += format_description( o, OPTION_DESC_GAP, allowed ); + result += '\n'; + } + } + return result; }