From 1b2f44572bdb93015f12d98ee4447996ab8d28e5 Mon Sep 17 00:00:00 2001 From: Pavel Belikov Date: Tue, 12 Dec 2017 20:46:40 +0300 Subject: add more GetChoicesString overrides --- args.hxx | 80 ++++++++++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 60 insertions(+), 20 deletions(-) (limited to 'args.hxx') diff --git a/args.hxx b/args.hxx index a8818ab..549fd54 100644 --- a/args.hxx +++ b/args.hxx @@ -869,6 +869,13 @@ namespace args defaultString = str; } + /** Gets default value string that will be added to argument description. + */ + std::string HelpDefault(const HelpParams ¶ms) const + { + return GetDefaultString(params); + } + /** Sets choices string that will be added to argument description. * Use empty string to disable it for this argument. */ @@ -878,6 +885,13 @@ namespace args choicesString = str; } + /** Gets choices string that will be added to argument description. + */ + std::string HelpChoices(const HelpParams ¶ms) const + { + return GetChoicesString(params); + } + virtual std::vector> GetDescription(const HelpParams ¶ms, const unsigned indentLevel) const override { std::tuple description; @@ -947,12 +961,39 @@ namespace args s << value; return s.str(); } + template typename std::enable_if::value, std::string>::type ToString(const T &) { return {}; } + + template + std::string MapKeysToString(const T &map) + { + std::string res; + using K = typename std::decayfirst)>::type; + if (IsConvertableToString::value) + { + std::vector values; + for (const auto &p : map) + { + values.push_back(detail::ToString(p.first)); + } + + std::sort(values.begin(), values.end()); + for (const auto &s : values) + { + if (!res.empty()) + { + res += ", "; + } + res += s; + } + } + return res; + } } /** Base class for all flag options @@ -3188,26 +3229,7 @@ namespace args protected: virtual std::string GetChoicesString(const HelpParams &) const override { - std::string res; - if (detail::IsConvertableToString::value) - { - std::vector values; - for (const auto &p : map) - { - values.push_back(detail::ToString(p.first)); - } - - std::sort(values.begin(), values.end()); - for (const auto &s : values) - { - if (!res.empty()) - { - res += ", "; - } - res += s; - } - } - return res; + return detail::MapKeysToString(map); } public: @@ -3286,6 +3308,12 @@ namespace args Container values; Reader reader; + protected: + virtual std::string GetChoicesString(const HelpParams &) const override + { + return detail::MapKeysToString(map); + } + public: typedef T value_type; typedef typename Container::allocator_type allocator_type; @@ -3557,6 +3585,12 @@ namespace args T value; Reader reader; + protected: + virtual std::string GetChoicesString(const HelpParams &) const override + { + return detail::MapKeysToString(map); + } + public: MapPositional(Group &group_, const std::string &name_, const std::string &help_, const Map &map_, const T &defaultValue_ = T()): PositionalBase(name_, help_), map(map_), value(defaultValue_) @@ -3626,6 +3660,12 @@ namespace args Container values; Reader reader; + protected: + virtual std::string GetChoicesString(const HelpParams &) const override + { + return detail::MapKeysToString(map); + } + public: typedef T value_type; typedef typename Container::allocator_type allocator_type; -- cgit v1.2.1