drogon_ctl add help command
This commit is contained in:
parent
56542a68d2
commit
aea79fd9a8
|
@ -8,5 +8,6 @@ class CommandHandler:public virtual drogon::DrObjectBase {
|
|||
public:
|
||||
|
||||
virtual void handleCommand(const std::vector<std::string> ¶meters)=0;
|
||||
virtual std::string script(){return "";}
|
||||
virtual ~CommandHandler(){}
|
||||
};
|
|
@ -0,0 +1,29 @@
|
|||
#include "help.h"
|
||||
#include <drogon/DrClassMap.h>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
using namespace drogon_ctl;
|
||||
void help::handleCommand(const std::vector<std::string> ¶meters)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
#pragma once
|
||||
|
||||
#include <drogon/DrObject.h>
|
||||
#include "CommandHandler.h"
|
||||
using namespace drogon;
|
||||
namespace drogon_ctl
|
||||
{
|
||||
class help:public DrObject<help>,public CommandHandler
|
||||
{
|
||||
public:
|
||||
void handleCommand(const std::vector<std::string> ¶meters);
|
||||
std::string script(){return "display this message";}
|
||||
};
|
||||
}
|
|
@ -9,6 +9,7 @@ namespace drogon_ctl
|
|||
{
|
||||
public:
|
||||
void handleCommand(const std::vector<std::string> ¶meters);
|
||||
std::string script(){return "display version of this tool";}
|
||||
version(){}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -27,9 +27,10 @@ class DrClassMap
|
|||
public:
|
||||
static void registerClass(const std::string &className,const DrAllocFunc &func);
|
||||
static DrObjectBase* newObject(const std::string &className);
|
||||
static std::vector<std::string> getAllClassName();
|
||||
protected:
|
||||
|
||||
static std::map <std::string,DrAllocFunc> &getMap();
|
||||
|
||||
};
|
||||
}
|
||||
#endif /* DrClassMap_hpp */
|
||||
|
|
|
@ -27,7 +27,15 @@ DrObjectBase* DrClassMap::newObject(const std::string &className)
|
|||
else
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::vector<std::string> DrClassMap::getAllClassName()
|
||||
{
|
||||
std::vector<std::string> ret;
|
||||
for(auto iter:getMap())
|
||||
{
|
||||
ret.push_back(iter.first);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
std::map <std::string,DrAllocFunc> & DrClassMap::getMap() {
|
||||
static std::map <std::string,DrAllocFunc> map;
|
||||
return map;
|
||||
|
|
Loading…
Reference in New Issue