Skip to content

Commit

Permalink
Maintain order of sub-commands in help printout
Browse files Browse the repository at this point in the history
  • Loading branch information
attah committed Feb 25, 2024
1 parent 5064b62 commit b74d2e0
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/argget.h
Original file line number Diff line number Diff line change
Expand Up @@ -376,10 +376,11 @@ class SubArgGet
SubArgGet(const SubArgGet&) = delete;
SubArgGet& operator=(const SubArgGet&) = delete;

SubArgGet(std::map<std::string, std::pair<std::list<SwitchArgBase*>, std::list<PosArg*>>> map)
SubArgGet(std::list<std::pair<std::string, std::pair<std::list<SwitchArgBase*>, std::list<PosArg*>>>> map)
{
for(const auto& [subCommand, args] : map)
{
_order.push_back(subCommand);
_subCommands[subCommand] = ArgGet(args.first, args.second);
}
}
Expand Down Expand Up @@ -432,9 +433,9 @@ class SubArgGet
}
else
{
for(const auto& [subCommand, argGet] : _subCommands)
for(std::string subCommand : _order)
{
help << _name << " " << subCommand << argGet._argHelp() << std::endl;
help << _name << " " << subCommand << _subCommands.at(subCommand)._argHelp() << std::endl;
}
}
return help.str();
Expand All @@ -454,6 +455,7 @@ class SubArgGet
std::string _name;
std::string _subCommand;
std::map<std::string, ArgGet> _subCommands;
std::list<std::string> _order;
std::string _errMsg;

};
Expand Down

0 comments on commit b74d2e0

Please sign in to comment.