From beb7ae2b5d47f29fe63f65e53ac42c1b0086b46a Mon Sep 17 00:00:00 2001 From: an-tao <20741618@qq.com> Date: Thu, 7 Jun 2018 18:16:30 +0800 Subject: [PATCH] modify drogon_ctl help command --- drogon_ctl/CommandHandler.h | 1 + drogon_ctl/create.cc | 11 +++++++- drogon_ctl/create.h | 1 + drogon_ctl/create_controller.h | 3 +-- drogon_ctl/help.cc | 48 ++++++++++++++++++++++++---------- 5 files changed, 47 insertions(+), 17 deletions(-) diff --git a/drogon_ctl/CommandHandler.h b/drogon_ctl/CommandHandler.h index 18742d76..c06bb511 100755 --- a/drogon_ctl/CommandHandler.h +++ b/drogon_ctl/CommandHandler.h @@ -24,5 +24,6 @@ public: virtual void handleCommand(std::vector ¶meters)=0; virtual bool isTopCommand(){return false;} virtual std::string script(){return "";} + virtual std::string detail(){return "";} virtual ~CommandHandler(){} }; \ No newline at end of file diff --git a/drogon_ctl/create.cc b/drogon_ctl/create.cc index 8a5859d9..8d05c096 100755 --- a/drogon_ctl/create.cc +++ b/drogon_ctl/create.cc @@ -19,7 +19,16 @@ #include #include 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 [-options] \n" + "drogon_ctl create view //create HttpView source files from csp file\n" + "drogon_ctl create controller [-s] [-n ] //" + "create HttpSimpleController source files\n" + "drogon_ctl create controller -a <[namespace::]class_name> //" + "create HttpApiController source files\n"; +} void create::handleCommand(std::vector ¶meters) { diff --git a/drogon_ctl/create.h b/drogon_ctl/create.h index c7a6250f..1d6f4db8 100755 --- a/drogon_ctl/create.h +++ b/drogon_ctl/create.h @@ -25,5 +25,6 @@ namespace drogon_ctl virtual void handleCommand(std::vector ¶meters) override; virtual std::string script() override {return "create controller or view class files";} virtual bool isTopCommand() override {return true;} + virtual std::string detail() override; }; } diff --git a/drogon_ctl/create_controller.h b/drogon_ctl/create_controller.h index d0e38dae..3373594a 100755 --- a/drogon_ctl/create_controller.h +++ b/drogon_ctl/create_controller.h @@ -23,8 +23,7 @@ namespace drogon_ctl { public: virtual void handleCommand(std::vector ¶meters) override; - std::string script(){return "create controller files";} - + virtual std::string script() override {return "create controller files";} protected: enum ControllerType{ Simple=0, diff --git a/drogon_ctl/help.cc b/drogon_ctl/help.cc index f8eadc5d..cff3e690 100755 --- a/drogon_ctl/help.cc +++ b/drogon_ctl/help.cc @@ -19,27 +19,47 @@ using namespace drogon_ctl; void help::handleCommand(std::vector ¶meters) { - std::cout<<"usage: drogon_ctl []"<(drogon::DrClassMap::newObject(className)); + std::cout<<"usage: drogon_ctl []"<(drogon::DrClassMap::newObject(className)); + if(classPtr) + { + auto cmdHdlPtr=std::dynamic_pointer_cast(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<script()<(drogon::DrClassMap::newObject(cmd)); if(classPtr) { auto cmdHdlPtr=std::dynamic_pointer_cast(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<script()<isTopCommand()) + std::cout<detail()<