Conditionally output all help groups on empty groups vector (#42)
* Conditionally output all help groups on empty groups vector * Fix formatting
This commit is contained in:
parent
3c3d2003ca
commit
21591dc8e8
@ -802,6 +802,14 @@ namespace cxxopts
|
|||||||
String
|
String
|
||||||
help_one_group(const std::string& group) const;
|
help_one_group(const std::string& group) const;
|
||||||
|
|
||||||
|
inline
|
||||||
|
void
|
||||||
|
generate_group_help(String& result, const std::vector<std::string>& groups) const;
|
||||||
|
|
||||||
|
inline
|
||||||
|
void
|
||||||
|
generate_all_groups_help(String& result) const;
|
||||||
|
|
||||||
std::string m_program;
|
std::string m_program;
|
||||||
String m_help_string;
|
String m_help_string;
|
||||||
std::string m_positional_help;
|
std::string m_positional_help;
|
||||||
@ -1372,6 +1380,35 @@ Options::help_one_group(const std::string& g) const
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Options::generate_group_help(String& result, const std::vector<std::string>& groups) const
|
||||||
|
{
|
||||||
|
for (std::size_t i = 0; i < groups.size(); ++i)
|
||||||
|
{
|
||||||
|
String const& group_help = help_one_group(groups[i]);
|
||||||
|
if (empty(group_help)) continue;
|
||||||
|
result += group_help;
|
||||||
|
if (i < groups.size() - 1)
|
||||||
|
{
|
||||||
|
result += '\n';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Options::generate_all_groups_help(String& result) const
|
||||||
|
{
|
||||||
|
std::vector<std::string> groups;
|
||||||
|
groups.reserve(m_help.size());
|
||||||
|
|
||||||
|
for (auto& group : m_help)
|
||||||
|
{
|
||||||
|
groups.push_back(group.first);
|
||||||
|
}
|
||||||
|
|
||||||
|
generate_group_help(result, groups);
|
||||||
|
}
|
||||||
|
|
||||||
std::string
|
std::string
|
||||||
Options::help(const std::vector<std::string>& groups) const
|
Options::help(const std::vector<std::string>& groups) const
|
||||||
{
|
{
|
||||||
@ -1384,15 +1421,13 @@ Options::help(const std::vector<std::string>& groups) const
|
|||||||
|
|
||||||
result += "\n\n";
|
result += "\n\n";
|
||||||
|
|
||||||
for (std::size_t i = 0; i < groups.size(); ++i)
|
if (groups.size() == 0)
|
||||||
{
|
{
|
||||||
String const& group_help = help_one_group(groups[i]);
|
generate_all_groups_help(result);
|
||||||
if (empty(group_help)) continue;
|
}
|
||||||
result += group_help;
|
else
|
||||||
if (i < groups.size() - 1)
|
{
|
||||||
{
|
generate_group_help(result, groups);
|
||||||
result += '\n';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return toUTF8String(result);
|
return toUTF8String(result);
|
||||||
|
Loading…
Reference in New Issue
Block a user