2018-10-07 03:38:44 +00:00
|
|
|
#pragma once
|
2015-06-10 02:40:03 +00:00
|
|
|
|
|
|
|
#include "ToolBase.hpp"
|
2017-12-29 07:56:31 +00:00
|
|
|
#include <cstdio>
|
2015-06-10 02:40:03 +00:00
|
|
|
#include <functional>
|
|
|
|
|
2018-12-08 05:18:42 +00:00
|
|
|
class ToolHelp final : public ToolBase {
|
2015-06-10 02:40:03 +00:00
|
|
|
|
|
|
|
public:
|
2019-08-20 02:49:24 +00:00
|
|
|
explicit ToolHelp(const ToolPassInfo& info) : ToolBase(info) {
|
2018-12-08 05:18:42 +00:00
|
|
|
if (m_info.args.empty()) {
|
2020-04-11 22:48:11 +00:00
|
|
|
LogModule.report(logvisor::Error, FMT_STRING("help requires a tool name argument"));
|
2018-12-08 05:18:42 +00:00
|
|
|
return;
|
2015-06-10 02:40:03 +00:00
|
|
|
}
|
2018-12-08 05:18:42 +00:00
|
|
|
m_good = true;
|
|
|
|
}
|
2015-06-10 02:40:03 +00:00
|
|
|
|
2019-08-20 02:34:12 +00:00
|
|
|
~ToolHelp() override = default;
|
2015-06-10 02:40:03 +00:00
|
|
|
|
2018-12-08 05:18:42 +00:00
|
|
|
static void Help(HelpOutput& help) {
|
2020-04-10 03:19:33 +00:00
|
|
|
/* clang-format off */
|
2018-12-08 05:18:42 +00:00
|
|
|
help.printBold(
|
2020-04-10 03:19:33 +00:00
|
|
|
_SYS_STR(" ___________ \n")
|
|
|
|
_SYS_STR(" ,.-'\"...........``~., \n")
|
|
|
|
_SYS_STR(" ,.-\".......................\"-., \n")
|
|
|
|
_SYS_STR(" ,/..................................\":, \n")
|
|
|
|
_SYS_STR(" .,?........................................, \n")
|
|
|
|
_SYS_STR(" /...........................................,}\n")
|
|
|
|
_SYS_STR(" ./........................................,:`^`..}\n")
|
|
|
|
_SYS_STR(" ./.......................................,:\"...../\n")
|
|
|
|
_SYS_STR(" ?.....__..................................:`...../\n")
|
|
|
|
_SYS_STR(" /__.(...\"~-,_...........................,:`....../\n")
|
|
|
|
_SYS_STR(" /(_....\"~,_....\"~,_.....................,:`...._/ \n")
|
|
|
|
_SYS_STR(" {.._$;_....\"=,_.....\"-,_......,.-~-,},.~\";/....} \n")
|
|
|
|
_SYS_STR(" ((...*~_......\"=-._...\";,,./`........../\"..../ \n")
|
|
|
|
_SYS_STR(" ,,,___.`~,......\"~.,....................`......}....../ \n")
|
|
|
|
_SYS_STR("............(....`=-,,...`.........................(...;_,,-\" \n")
|
|
|
|
_SYS_STR("............/.`~,......`-.................................../ \n")
|
|
|
|
_SYS_STR(".............`~.*-,.....................................|,./...,__ \n")
|
|
|
|
_SYS_STR(",,_..........}.>-._...................................|.......`=~-, \n")
|
|
|
|
_SYS_STR(".....`=~-,__......`,................................. \n")
|
|
|
|
_SYS_STR("...................`=~-,,.,........................... \n")
|
|
|
|
_SYS_STR(".........................`:,,..........................`\n")
|
|
|
|
_SYS_STR("...........................`=-,...............,%%`>--==`` \n")
|
|
|
|
_SYS_STR(".................................._.........._,-%%...` \n")
|
|
|
|
_SYS_STR("...................................,\n"));
|
|
|
|
/* clang-format on */
|
2018-12-08 05:18:42 +00:00
|
|
|
}
|
2015-06-10 02:40:03 +00:00
|
|
|
|
2018-12-08 05:18:42 +00:00
|
|
|
static void ShowHelp(const hecl::SystemString& toolName) {
|
|
|
|
/* Select tool's help-text streamer */
|
2019-08-20 02:52:33 +00:00
|
|
|
HelpOutput::HelpFunc helpFunc = nullptr;
|
2018-12-08 05:18:42 +00:00
|
|
|
if (toolName == _SYS_STR("init"))
|
|
|
|
helpFunc = ToolInit::Help;
|
|
|
|
else if (toolName == _SYS_STR("spec"))
|
|
|
|
helpFunc = ToolSpec::Help;
|
|
|
|
else if (toolName == _SYS_STR("extract"))
|
|
|
|
helpFunc = ToolExtract::Help;
|
|
|
|
else if (toolName == _SYS_STR("cook"))
|
|
|
|
helpFunc = ToolCook::Help;
|
|
|
|
else if (toolName == _SYS_STR("package") || toolName == _SYS_STR("pack"))
|
|
|
|
helpFunc = ToolPackage::Help;
|
|
|
|
else if (toolName == _SYS_STR("help"))
|
|
|
|
helpFunc = ToolHelp::Help;
|
|
|
|
else {
|
2020-04-11 22:48:11 +00:00
|
|
|
LogModule.report(logvisor::Error, FMT_STRING(_SYS_STR("unrecognized tool '{}' - can't help")), toolName);
|
2018-12-08 05:18:42 +00:00
|
|
|
return;
|
2015-06-10 02:40:03 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:18:42 +00:00
|
|
|
HelpOutput ho(helpFunc);
|
|
|
|
ho.go();
|
|
|
|
}
|
2015-06-10 02:40:03 +00:00
|
|
|
|
2020-04-10 03:19:33 +00:00
|
|
|
hecl::SystemStringView toolName() const override { return _SYS_STR("help"sv); }
|
2015-06-10 02:40:03 +00:00
|
|
|
|
2019-08-20 02:34:12 +00:00
|
|
|
int run() override {
|
2018-12-08 05:18:42 +00:00
|
|
|
ShowHelp(m_info.args.front());
|
|
|
|
return 0;
|
|
|
|
}
|
2015-06-10 02:40:03 +00:00
|
|
|
};
|