Skip to content

Commit

Permalink
preserve order of groups
Browse files Browse the repository at this point in the history
  • Loading branch information
artpaul committed Nov 10, 2024
1 parent 2268347 commit d31d831
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions include/cxxopts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1847,15 +1847,7 @@ class options {
* Returns list of the defined groups.
*/
std::vector<std::string> groups() const {
std::vector<std::string> names;

names.reserve(help_.size());

for (auto hi = help_.cbegin(); hi != help_.cend(); ++hi) {
names.push_back(hi->first);
}

return names;
return group_names_;
}

const help_group_details& group_help(const std::string& group) const {
Expand Down Expand Up @@ -1883,6 +1875,9 @@ class options {
add_one_option(l, details);
}

if (help_.find(group) == help_.end()) {
group_names_.push_back(group);
}
// Add the help details.
help_[group].options.push_back(std::move(details));
}
Expand Down Expand Up @@ -2031,7 +2026,7 @@ class options {
}

void generate_all_groups_help(cxx_string& result) const {
generate_group_help(result, groups());
generate_group_help(result, group_names_);
}

cxx_string expand_tab_character(const cxx_string& text) const {
Expand Down Expand Up @@ -2171,6 +2166,8 @@ class options {
std::unordered_set<std::string> positional_set_{};
/// Mapping from groups to help options.
std::map<std::string, help_group_details> help_{};
/// Unique names of groups in order defined by user.
std::vector<std::string> group_names_{};
};

} // namespace cxxopts
Expand Down

0 comments on commit d31d831

Please sign in to comment.