2018-05-31 17:00:31 +08: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 13:49:26 +08:00
|
|
|
|
|
|
|
#include "cmd.h"
|
|
|
|
#include "CommandHandler.h"
|
|
|
|
#include <drogon/DrClassMap.h>
|
|
|
|
#include <memory>
|
|
|
|
using namespace drogon;
|
|
|
|
|
2018-10-14 15:56:54 +08:00
|
|
|
void exeCommand(std::vector<std::string> ¶meters)
|
2018-05-29 13:49:26 +08:00
|
|
|
{
|
2018-10-14 15:56:54 +08:00
|
|
|
if (parameters.empty())
|
2018-05-29 13:49:26 +08:00
|
|
|
{
|
2018-10-14 15:56:54 +08:00
|
|
|
std::cout << "incomplete command!use help command to get usage!" << std::endl;
|
2018-05-29 13:49:26 +08:00
|
|
|
return;
|
|
|
|
}
|
2018-10-14 15:56:54 +08:00
|
|
|
std::string command = parameters[0];
|
2018-05-29 13:49:26 +08:00
|
|
|
|
2018-10-14 15:56:54 +08:00
|
|
|
std::string handlerName = std::string("drogon_ctl::").append(command);
|
2018-05-29 13:49:26 +08:00
|
|
|
|
|
|
|
parameters.erase(parameters.begin());
|
|
|
|
|
|
|
|
//new command handler to do cmd
|
2018-10-14 15:56:54 +08:00
|
|
|
auto obj = std::shared_ptr<DrObjectBase>(drogon::DrClassMap::newObject(handlerName));
|
|
|
|
if (obj)
|
2018-05-29 13:49:26 +08:00
|
|
|
{
|
2018-10-14 15:56:54 +08:00
|
|
|
auto ctl = std::dynamic_pointer_cast<CommandHandler>(obj);
|
|
|
|
if (ctl)
|
2018-05-29 13:49:26 +08:00
|
|
|
{
|
|
|
|
ctl->handleCommand(parameters);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-10-14 15:56:54 +08:00
|
|
|
std::cout << "command not found!use help command to get usage!" << std::endl;
|
2018-05-29 13:49:26 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-10-14 15:56:54 +08:00
|
|
|
std::cout << "command error!use help command to get usage!" << std::endl;
|
2018-05-29 13:49:26 +08:00
|
|
|
}
|
|
|
|
}
|