drogon/drogon_ctl/cmd.cc

57 lines
1.3 KiB
C++
Raw Normal View History

2018-05-31 09:00:31 +00:00
/**
*
2018-12-07 07:50:18 +00:00
* cmd.cc
* An Tao
2018-05-31 09:00:31 +00:00
*
* Copyright 2018, An Tao. All rights reserved.
2018-12-07 07:50:18 +00:00
* https://github.com/an-tao/drogon
2018-05-31 09:00:31 +00:00
* Use of this source code is governed by a MIT license
* that can be found in the License file.
*
2018-11-16 05:26:14 +00:00
* Drogon
2018-05-31 09:00:31 +00:00
*
*/
#include "cmd.h"
#include "CommandHandler.h"
#include <drogon/DrClassMap.h>
#include <memory>
using namespace drogon;
2018-10-14 07:56:54 +00:00
void exeCommand(std::vector<std::string> &parameters)
{
2018-10-14 07:56:54 +00:00
if (parameters.empty())
{
2019-05-18 12:39:57 +00:00
std::cout << "incomplete command!use help command to get usage!"
<< std::endl;
return;
}
2018-10-14 07:56:54 +00:00
std::string command = parameters[0];
2018-10-14 07:56:54 +00:00
std::string handlerName = std::string("drogon_ctl::").append(command);
parameters.erase(parameters.begin());
2019-05-18 12:39:57 +00:00
// new command handler to do cmd
auto obj = std::shared_ptr<DrObjectBase>(
drogon::DrClassMap::newObject(handlerName));
2018-10-14 07:56:54 +00:00
if (obj)
{
2018-10-14 07:56:54 +00:00
auto ctl = std::dynamic_pointer_cast<CommandHandler>(obj);
if (ctl)
{
ctl->handleCommand(parameters);
}
else
{
2019-05-18 12:39:57 +00:00
std::cout << "command not found!use help command to get usage!"
<< std::endl;
}
}
else
{
2019-05-18 12:39:57 +00:00
std::cout << "command error!use help command to get usage!"
<< std::endl;
}
2018-11-16 05:26:14 +00:00
}