Skip to content

Commit b74d2e0

Browse files
committed
Maintain order of sub-commands in help printout
1 parent 5064b62 commit b74d2e0

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

lib/argget.h

+5-3
Original file line numberDiff line numberDiff line change
@@ -376,10 +376,11 @@ class SubArgGet
376376
SubArgGet(const SubArgGet&) = delete;
377377
SubArgGet& operator=(const SubArgGet&) = delete;
378378

379-
SubArgGet(std::map<std::string, std::pair<std::list<SwitchArgBase*>, std::list<PosArg*>>> map)
379+
SubArgGet(std::list<std::pair<std::string, std::pair<std::list<SwitchArgBase*>, std::list<PosArg*>>>> map)
380380
{
381381
for(const auto& [subCommand, args] : map)
382382
{
383+
_order.push_back(subCommand);
383384
_subCommands[subCommand] = ArgGet(args.first, args.second);
384385
}
385386
}
@@ -432,9 +433,9 @@ class SubArgGet
432433
}
433434
else
434435
{
435-
for(const auto& [subCommand, argGet] : _subCommands)
436+
for(std::string subCommand : _order)
436437
{
437-
help << _name << " " << subCommand << argGet._argHelp() << std::endl;
438+
help << _name << " " << subCommand << _subCommands.at(subCommand)._argHelp() << std::endl;
438439
}
439440
}
440441
return help.str();
@@ -454,6 +455,7 @@ class SubArgGet
454455
std::string _name;
455456
std::string _subCommand;
456457
std::map<std::string, ArgGet> _subCommands;
458+
std::list<std::string> _order;
457459
std::string _errMsg;
458460

459461
};

0 commit comments

Comments
 (0)