Skip to content

Commit

Permalink
Ordered vector of group names to preserve order of groups (#416)
Browse files Browse the repository at this point in the history
Co-authored-by: Nigel Stewart <[email protected]>
  • Loading branch information
nigels-com and Nigel Stewart authored Jan 15, 2024
1 parent 554396b commit cd61c68
Showing 1 changed file with 9 additions and 26 deletions.
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

0 comments on commit cd61c68

Please sign in to comment.