From 8c9249a8c634a111f8e5d34252b35dfaaa43685f Mon Sep 17 00:00:00 2001 From: Jarryd Beck Date: Fri, 10 Oct 2014 17:29:49 +1100 Subject: [PATCH] reorganise --- src/cxxopts.cpp | 66 +++++++++++++++++++++++++++++++++---------------- src/cxxopts.hpp | 36 +++++++++++++++++++++++++-- 2 files changed, 79 insertions(+), 23 deletions(-) diff --git a/src/cxxopts.cpp b/src/cxxopts.cpp index a6baeec..2534be0 100644 --- a/src/cxxopts.cpp +++ b/src/cxxopts.cpp @@ -62,27 +62,7 @@ OptionAdder::operator() const auto& s = result[2]; const auto& l = result[3]; - auto option = std::make_shared(desc, value); - - if (s.length() != 0) - { - auto in = m_options.m_options.insert(std::make_pair(s.str(), option)); - - if (!in.second) - { - throw option_exists_error(s.str()); - } - } - - if (l.length() != 0) - { - auto in = m_options.m_options.insert(std::make_pair(l, option)); - - if (!in.second) - { - throw option_exists_error(l.str()); - } - } + m_options.add_option(s.str(), l.str(), desc, value); return *this; } @@ -268,4 +248,48 @@ Options::parse(int& argc, char**& argv) argc = nextKeep; } +void +Options::add_option +( + const std::string& s, + const std::string& l, + const std::string& desc, + std::shared_ptr value +) +{ + auto option = std::make_shared(desc, value); + + add_one_option(s, option); + add_one_option(l, option); + + //add the help details +} + +void +Options::add_one_option +( + const std::string& option, + std::shared_ptr details +) +{ + auto in = m_options.insert(std::make_pair(option, details)); + + if (!in.second) + { + throw option_exists_error(option); + } +} + +std::string +Options::help() const +{ + auto group = m_help.find(""); + if (group == m_help.end()) + { + return ""; + } + + return ""; +} + } diff --git a/src/cxxopts.hpp b/src/cxxopts.hpp index c684aec..0db994e 100644 --- a/src/cxxopts.hpp +++ b/src/cxxopts.hpp @@ -286,6 +286,18 @@ namespace cxxopts int m_count; }; + class HelpDetails + { + public: + HelpDetails(); + + private: + std::string m_short; + std::string m_long; + std::string m_description; + bool m_arg; + }; + class Options { public: @@ -296,6 +308,15 @@ namespace cxxopts OptionAdder add_options(); + void + add_option + ( + const std::string& s, + const std::string& l, + const std::string& desc, + std::shared_ptr value + ); + int count(const std::string& o) const { @@ -325,8 +346,17 @@ namespace cxxopts void parse_positional(std::string option); + std::string + help() const; + private: - friend class OptionAdder; + + void + add_one_option + ( + const std::string& option, + std::shared_ptr details + ); bool consume_positional(std::string a); @@ -352,9 +382,11 @@ namespace cxxopts const std::string& name ); - std::map> m_options; std::string m_positional; + + //mapping from groups to help options + std::map> m_help; }; class OptionAdder