drogon/drogon_ctl/help.cc
Nikolay Mitev 17c80508c0 Drop cpp14 build (#1740)
* Drop C++14 Support

* Update README.md

* Remove drogon::optional in favor of std::optional

* Remove drogon::filesystem in favor of std::filesystem

* Remove boost::string_view and pre-c++17 hacks

* Remove boost::any

* Remove the string_view.h and the any.h

* Remove boost lib

* Update .clang-format and ci

Co-authored-by: Omar Mohamed <omar@omar-laptop.lan>
Co-authored-by: Ken Matsui <26405363+ken-matsui@users.noreply.github.com>
Co-authored-by: An Tao <antao2002@gmail.com>
Co-authored-by: albaropereyra22 <141711575+albaropereyra22@users.noreply.github.com>
Co-authored-by: Yoshihiro Hokazono <47231909+hokacci@users.noreply.github.com>
Co-authored-by: Omar Mohamed Khallaf <51155980+omarmohamedkh@users.noreply.github.com>
2023-08-23 11:49:55 +08:00

71 lines
2.0 KiB
C++

/**
*
* help.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 "help.h"
#include <drogon/DrClassMap.h>
#include <iostream>
#include <memory>
using namespace drogon_ctl;
void help::handleCommand(std::vector<std::string> &parameters)
{
if (parameters.size() == 0)
{
std::cout << "usage: drogon_ctl [-v | --version] [-h | --help] "
"<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())
std::cout << cmdHdlPtr->detail() << std::endl;
}
}
}
}