modify drogon_ctl help command

This commit is contained in:
an-tao 2018-06-07 18:16:30 +08:00
parent 696a2d016f
commit beb7ae2b5d
5 changed files with 47 additions and 17 deletions

View File

@ -24,5 +24,6 @@ public:
virtual void handleCommand(std::vector<std::string> &parameters)=0;
virtual bool isTopCommand(){return false;}
virtual std::string script(){return "";}
virtual std::string detail(){return "";}
virtual ~CommandHandler(){}
};

View File

@ -19,7 +19,16 @@
#include <iostream>
#include <memory>
using namespace drogon_ctl;
std::string create::detail()
{
return "Use create command to create some source files of drogon webapp\n"
"Usage:drogon_ctl create <view|controller> [-options] <object name>\n"
"drogon_ctl create view <csp file name> //create HttpView source files from csp file\n"
"drogon_ctl create controller [-s] [-n <namespace>] <class_name> //"
"create HttpSimpleController source files\n"
"drogon_ctl create controller -a <[namespace::]class_name> //"
"create HttpApiController source files\n";
}
void create::handleCommand(std::vector<std::string> &parameters)
{

View File

@ -25,5 +25,6 @@ namespace drogon_ctl
virtual void handleCommand(std::vector<std::string> &parameters) override;
virtual std::string script() override {return "create controller or view class files";}
virtual bool isTopCommand() override {return true;}
virtual std::string detail() override;
};
}

View File

@ -23,8 +23,7 @@ namespace drogon_ctl
{
public:
virtual void handleCommand(std::vector<std::string> &parameters) override;
std::string script(){return "create controller files";}
virtual std::string script() override {return "create controller files";}
protected:
enum ControllerType{
Simple=0,

View File

@ -19,27 +19,47 @@
using namespace drogon_ctl;
void help::handleCommand(std::vector<std::string> &parameters)
{
std::cout<<"usage: drogon_ctl <command> [<args>]"<<std::endl;
std::cout<<"commands list:"<<std::endl;
for(auto className:drogon::DrClassMap::getAllClassName())
if(parameters.size()==0)
{
auto classPtr=std::shared_ptr<DrObjectBase>(drogon::DrClassMap::newObject(className));
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)
{
if(!cmdHdlPtr->isTopCommand())
continue;
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;
}
}
}
}
else
{
auto cmd=std::string("drogon_ctl::")+parameters[0];
auto classPtr=std::shared_ptr<DrObjectBase>(drogon::DrClassMap::newObject(cmd));
if(classPtr)
{
auto cmdHdlPtr=std::dynamic_pointer_cast<CommandHandler>(classPtr);
if(cmdHdlPtr)
{
if(!cmdHdlPtr->isTopCommand())
continue;
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;
if(cmdHdlPtr->isTopCommand())
std::cout<<cmdHdlPtr->detail()<<std::endl;
}
}
}
}