Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ordered vector of group names to preserve order of groups #416

Merged
merged 1 commit into from
Jan 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 9 additions & 26 deletions include/cxxopts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2033,6 +2033,7 @@ class Options
std::unordered_set<std::string> m_positional_set{};

//mapping from groups to help options
std::vector<std::string> m_group{};
std::map<std::string, HelpGroupDetails> m_help{};
};

Expand Down Expand Up @@ -2671,6 +2672,12 @@ Options::add_option
}

//add the help details

if (m_help.find(group) == m_help.end())
{
m_group.push_back(group);
}

auto& options = m_help[group];

options.options.emplace_back(HelpOptionDetails{s, l, stringDesc,
Expand Down Expand Up @@ -2802,19 +2809,7 @@ inline
void
Options::generate_all_groups_help(String& result) const
{
std::vector<std::string> all_groups;

std::transform(
m_help.begin(),
m_help.end(),
std::back_inserter(all_groups),
[] (const std::map<std::string, HelpGroupDetails>::value_type& group)
{
return group.first;
}
);

generate_group_help(result, all_groups);
generate_group_help(result, m_group);
}

inline
Expand Down Expand Up @@ -2854,19 +2849,7 @@ inline
std::vector<std::string>
Options::groups() const
{
std::vector<std::string> g;

std::transform(
m_help.begin(),
m_help.end(),
std::back_inserter(g),
[] (const std::map<std::string, HelpGroupDetails>::value_type& pair)
{
return pair.first;
}
);

return g;
return m_group;
}

inline
Expand Down