| 516 | |
| 517 | |
| 518 | void cServer::PrintHelp(const AStringVector & a_Split, cCommandOutputCallback & a_Output) |
| 519 | { |
| 520 | UNUSED(a_Split); |
| 521 | typedef std::pair<AString, AString> AStringPair; |
| 522 | typedef std::vector<AStringPair> AStringPairs; |
| 523 | |
| 524 | class cCallback : |
| 525 | public cPluginManager::cCommandEnumCallback |
| 526 | { |
| 527 | public: |
| 528 | cCallback(void) : m_MaxLen(0) {} |
| 529 | |
| 530 | virtual bool Command(const AString & a_Command, const cPlugin * a_Plugin, const AString & a_Permission, const AString & a_HelpString) override |
| 531 | { |
| 532 | UNUSED(a_Plugin); |
| 533 | UNUSED(a_Permission); |
| 534 | if (!a_HelpString.empty()) |
| 535 | { |
| 536 | m_Commands.push_back(AStringPair(a_Command, a_HelpString)); |
| 537 | if (m_MaxLen < a_Command.length()) |
| 538 | { |
| 539 | m_MaxLen = a_Command.length(); |
| 540 | } |
| 541 | } |
| 542 | return false; |
| 543 | } |
| 544 | |
| 545 | AStringPairs m_Commands; |
| 546 | size_t m_MaxLen; |
| 547 | } Callback; |
| 548 | cPluginManager::Get()->ForEachConsoleCommand(Callback); |
| 549 | std::sort(Callback.m_Commands.begin(), Callback.m_Commands.end()); |
| 550 | for (AStringPairs::const_iterator itr = Callback.m_Commands.begin(), end = Callback.m_Commands.end(); itr != end; ++itr) |
| 551 | { |
| 552 | const AStringPair & cmd = *itr; |
| 553 | a_Output.Out(Printf("%-*s%s\n", static_cast<int>(Callback.m_MaxLen), cmd.first.c_str(), cmd.second.c_str())); |
| 554 | } // for itr - Callback.m_Commands[] |
| 555 | a_Output.Finished(); |
| 556 | } |
| 557 | |
| 558 | |
| 559 | |