forked from drogonframework/drogon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcmd.cc
56 lines (51 loc) · 1.28 KB
/
cmd.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/**
*
* cmd.cc
* An Tao
*
* Copyright 2018, An Tao. All rights reserved.
* https://github.com/an-tao/drogon
* Use of this source code is governed by a MIT license
* that can be found in the License file.
*
* Drogon
*
*/
#include "cmd.h"
#include "CommandHandler.h"
#include <drogon/DrClassMap.h>
#include <memory>
using namespace drogon;
void exeCommand(std::vector<std::string> ¶meters)
{
if (parameters.empty())
{
std::cout << "incomplete command!use help command to get usage!"
<< std::endl;
return;
}
std::string command = parameters[0];
std::string handlerName = std::string("drogon_ctl::").append(command);
parameters.erase(parameters.begin());
// new command handler to do cmd
auto obj = std::shared_ptr<DrObjectBase>(
drogon::DrClassMap::newObject(handlerName));
if (obj)
{
auto ctl = std::dynamic_pointer_cast<CommandHandler>(obj);
if (ctl)
{
ctl->handleCommand(parameters);
}
else
{
std::cout << "command not found!use help command to get usage!"
<< std::endl;
}
}
else
{
std::cout << "command error!use help command to get usage!"
<< std::endl;
}
}