From 30610a2e8ca3bfb7f7b87fb8514dee1705803bac Mon Sep 17 00:00:00 2001 From: "Taylor C. Richberger" Date: Fri, 6 May 2016 13:52:07 -0600 Subject: add groups to help output: --- args.hxx | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/args.hxx b/args.hxx index da5f267..ea3c9ef 100644 --- a/args.hxx +++ b/args.hxx @@ -547,23 +547,26 @@ namespace args /** Get all the child descriptions for help generation */ - std::vector> GetChildDescriptions(const std::string &shortPrefix, const std::string &longPrefix) const + std::vector> GetChildDescriptions(const std::string &shortPrefix, const std::string &longPrefix, unsigned int indent = 0) const { - std::vector> descriptions; + std::vector> descriptions; for (const auto &child: children) { const Group *group = dynamic_cast(child); const NamedBase *named = dynamic_cast(child); if (group) { - std::vector> groupDescriptions(group->GetChildDescriptions(shortPrefix, longPrefix)); + // Push that group description on the back: + descriptions.emplace_back("", group->help, indent); + std::vector> groupDescriptions(group->GetChildDescriptions(shortPrefix, longPrefix, indent + 1)); descriptions.insert( std::end(descriptions), std::make_move_iterator(std::begin(groupDescriptions)), std::make_move_iterator(std::end(groupDescriptions))); } else if (named) { - descriptions.emplace_back(named->GetDescription(shortPrefix, longPrefix)); + const std::tuple description(named->GetDescription(shortPrefix, longPrefix)); + descriptions.emplace_back(std::get<0>(description), std::get<1>(description), indent); } } return descriptions; @@ -823,21 +826,25 @@ namespace args for (const auto &description: GetChildDescriptions(shortprefix, longprefix)) { const std::string &flags = std::get<0>(description); - const std::vector info(Wrap(std::get<1>(description), helpParams.width - helpParams.helpindent)); - help << std::string(helpParams.flagindent, ' ') << flags; + const unsigned int groupindent = std::get<2>(description) * helpParams.eachgroupindent; + const std::vector info(Wrap(std::get<1>(description), helpParams.width - (helpParams.helpindent + groupindent))); + + help << std::string(groupindent + helpParams.flagindent, ' ') << flags; auto infoit = std::begin(info); const std::string::size_type flagssize = Glyphs(flags); + // groupindent is on both sides of this inequality, and therefore can be removed if ((helpParams.flagindent + flagssize + helpParams.gutter) > helpParams.helpindent) { help << '\n'; } else if (infoit != std::end(info)) { + // groupindent is on both sides of the minus sign, and therefore doesn't actually need to be in here help << std::string(helpParams.helpindent - (helpParams.flagindent + flagssize), ' ') << *infoit << '\n'; ++infoit; } for (; infoit != std::end(info); ++infoit) { - help << std::string(helpParams.helpindent, ' ') << *infoit << '\n'; + help << std::string(groupindent + helpParams.helpindent, ' ') << *infoit << '\n'; } } if (hasoptions && hasarguments) -- cgit v1.2.1