2018-05-31 17:00:31 +08:00
|
|
|
/**
|
|
|
|
*
|
2018-12-07 15:50:18 +08:00
|
|
|
* help.cc
|
|
|
|
* An Tao
|
2018-05-31 17:00:31 +08:00
|
|
|
*
|
|
|
|
* Copyright 2018, An Tao. All rights reserved.
|
2018-12-07 15:50:18 +08:00
|
|
|
* https://github.com/an-tao/drogon
|
2018-05-31 17:00:31 +08:00
|
|
|
* Use of this source code is governed by a MIT license
|
|
|
|
* that can be found in the License file.
|
|
|
|
*
|
2018-11-16 13:26:14 +08:00
|
|
|
* Drogon
|
2018-05-31 17:00:31 +08:00
|
|
|
*
|
|
|
|
*/
|
2018-05-29 13:49:26 +08:00
|
|
|
|
2018-05-28 18:29:14 +08:00
|
|
|
#include "help.h"
|
|
|
|
#include <drogon/DrClassMap.h>
|
|
|
|
#include <iostream>
|
|
|
|
#include <memory>
|
|
|
|
using namespace drogon_ctl;
|
2018-05-29 13:49:26 +08:00
|
|
|
void help::handleCommand(std::vector<std::string> ¶meters)
|
2018-05-28 18:29:14 +08:00
|
|
|
{
|
2018-10-14 15:56:54 +08:00
|
|
|
if (parameters.size() == 0)
|
2018-05-28 18:29:14 +08:00
|
|
|
{
|
2018-10-14 15:56:54 +08:00
|
|
|
std::cout << "usage: drogon_ctl <command> [<args>]" << std::endl;
|
|
|
|
std::cout << "commands list:" << std::endl;
|
2019-01-21 17:32:49 +08:00
|
|
|
for (auto &className : drogon::DrClassMap::getAllClassName())
|
2018-06-07 18:16:30 +08:00
|
|
|
{
|
2019-05-18 20:39:57 +08:00
|
|
|
auto classPtr = std::shared_ptr<DrObjectBase>(
|
|
|
|
drogon::DrClassMap::newObject(className));
|
2018-10-14 15:56:54 +08:00
|
|
|
if (classPtr)
|
2018-06-07 18:16:30 +08:00
|
|
|
{
|
2019-05-18 20:39:57 +08:00
|
|
|
auto cmdHdlPtr =
|
|
|
|
std::dynamic_pointer_cast<CommandHandler>(classPtr);
|
2018-10-14 15:56:54 +08:00
|
|
|
if (cmdHdlPtr)
|
2018-06-07 18:16:30 +08:00
|
|
|
{
|
2018-10-14 15:56:54 +08:00
|
|
|
if (!cmdHdlPtr->isTopCommand())
|
2018-06-07 18:16:30 +08:00
|
|
|
continue;
|
2018-10-14 15:56:54 +08:00
|
|
|
auto pos = className.rfind("::");
|
|
|
|
if (pos != std::string::npos)
|
2018-06-07 18:16:30 +08:00
|
|
|
{
|
2018-10-14 15:56:54 +08:00
|
|
|
className = className.substr(pos + 2);
|
2018-06-07 18:16:30 +08:00
|
|
|
}
|
2018-10-14 15:56:54 +08:00
|
|
|
while (className.length() < 24)
|
2018-06-07 18:16:30 +08:00
|
|
|
className.append(" ");
|
2018-10-14 15:56:54 +08:00
|
|
|
std::cout << className << cmdHdlPtr->script() << std::endl;
|
2018-06-07 18:16:30 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-10-14 15:56:54 +08:00
|
|
|
auto cmd = std::string("drogon_ctl::") + parameters[0];
|
2018-06-07 18:16:30 +08:00
|
|
|
|
2019-05-18 20:39:57 +08:00
|
|
|
auto classPtr =
|
|
|
|
std::shared_ptr<DrObjectBase>(drogon::DrClassMap::newObject(cmd));
|
2018-10-14 15:56:54 +08:00
|
|
|
if (classPtr)
|
2018-05-28 18:29:14 +08:00
|
|
|
{
|
2019-05-18 20:39:57 +08:00
|
|
|
auto cmdHdlPtr =
|
|
|
|
std::dynamic_pointer_cast<CommandHandler>(classPtr);
|
2018-10-14 15:56:54 +08:00
|
|
|
if (cmdHdlPtr)
|
2018-05-28 18:29:14 +08:00
|
|
|
{
|
2018-10-14 15:56:54 +08:00
|
|
|
if (cmdHdlPtr->isTopCommand())
|
|
|
|
std::cout << cmdHdlPtr->detail() << std::endl;
|
2018-05-28 18:29:14 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-11-16 13:26:14 +08:00
|
|
|
}
|