2018-05-31 09:00:31 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
* @author An Tao
|
|
|
|
* @section LICENSE
|
|
|
|
*
|
|
|
|
* Copyright 2018, An Tao. All rights reserved.
|
|
|
|
* Use of this source code is governed by a MIT license
|
|
|
|
* that can be found in the License file.
|
|
|
|
*
|
|
|
|
* @section DESCRIPTION
|
|
|
|
*
|
|
|
|
*/
|
2018-05-29 05:49:26 +00:00
|
|
|
|
2018-05-28 10:29:14 +00:00
|
|
|
#include "help.h"
|
|
|
|
#include <drogon/DrClassMap.h>
|
|
|
|
#include <iostream>
|
|
|
|
#include <memory>
|
|
|
|
using namespace drogon_ctl;
|
2018-05-29 05:49:26 +00:00
|
|
|
void help::handleCommand(std::vector<std::string> ¶meters)
|
2018-05-28 10:29:14 +00:00
|
|
|
{
|
2018-06-07 10:16:30 +00:00
|
|
|
if(parameters.size()==0)
|
2018-05-28 10:29:14 +00:00
|
|
|
{
|
2018-06-07 10:16:30 +00:00
|
|
|
std::cout<<"usage: drogon_ctl <command> [<args>]"<<std::endl;
|
|
|
|
std::cout<<"commands list:"<<std::endl;
|
|
|
|
for(auto className:drogon::DrClassMap::getAllClassName())
|
|
|
|
{
|
|
|
|
auto classPtr=std::shared_ptr<DrObjectBase>(drogon::DrClassMap::newObject(className));
|
|
|
|
if(classPtr)
|
|
|
|
{
|
|
|
|
auto cmdHdlPtr=std::dynamic_pointer_cast<CommandHandler>(classPtr);
|
|
|
|
if(cmdHdlPtr)
|
|
|
|
{
|
|
|
|
if(!cmdHdlPtr->isTopCommand())
|
|
|
|
continue;
|
|
|
|
auto pos=className.rfind("::");
|
|
|
|
if(pos!=std::string::npos)
|
|
|
|
{
|
|
|
|
className=className.substr(pos+2);
|
|
|
|
}
|
|
|
|
while(className.length()<24)
|
|
|
|
className.append(" ");
|
|
|
|
std::cout<<className<<cmdHdlPtr->script()<<std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
auto cmd=std::string("drogon_ctl::")+parameters[0];
|
|
|
|
|
|
|
|
auto classPtr=std::shared_ptr<DrObjectBase>(drogon::DrClassMap::newObject(cmd));
|
2018-05-28 10:29:14 +00:00
|
|
|
if(classPtr)
|
|
|
|
{
|
|
|
|
auto cmdHdlPtr=std::dynamic_pointer_cast<CommandHandler>(classPtr);
|
|
|
|
if(cmdHdlPtr)
|
|
|
|
{
|
2018-06-07 10:16:30 +00:00
|
|
|
if(cmdHdlPtr->isTopCommand())
|
|
|
|
std::cout<<cmdHdlPtr->detail()<<std::endl;
|
|
|
|
|
2018-05-28 10:29:14 +00:00
|
|
|
}
|
|
|
|
}
|
2018-06-07 10:16:30 +00:00
|
|
|
|
2018-05-28 10:29:14 +00:00
|
|
|
}
|
|
|
|
}
|