drogon/drogon_ctl/main.cc

43 lines
978 B
C++
Raw Normal View History

2018-05-28 09:08:12 +00:00
#include "CommandHandler.h"
#include <drogon/DrClassMap.h>
2018-05-28 06:34:47 +00:00
#include <string>
#include <vector>
#include <iostream>
2018-05-28 09:08:12 +00:00
#include <memory>
using namespace drogon;
2018-05-28 06:34:47 +00:00
int main(int argc, char* argv[])
{
if(argc<2)
{
std::cout<<"usage:"<<std::endl;
return 0;
}
std::string command=argv[1];
2018-05-28 09:08:12 +00:00
std::string handlerName=std::string("drogon_ctl::").append(command);
//new controller
auto obj=std::shared_ptr<DrObjectBase>(drogon::DrClassMap::newObject(handlerName));
if(obj)
{
auto ctl=std::dynamic_pointer_cast<CommandHandler>(obj);
if(ctl)
{
std::vector<std::string> args;
for(int i=2;i<argc;i++)
{
args.push_back(argv[i]);
}
ctl->handleCommand(args);
}
else
{
std::cout<<"command not found!"<<std::endl;
}
}
else
2018-05-28 06:34:47 +00:00
{
2018-05-28 09:08:12 +00:00
std::cout<<"command error!"<<std::endl;
2018-05-28 06:34:47 +00:00
}
return 0;
}