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(
|
2021-06-30 18:20:45 +00:00
|
|
|
" ___________ \n"
|
|
|
|
" ,.-'\"...........``~., \n"
|
|
|
|
" ,.-\".......................\"-., \n"
|
|
|
|
" ,/..................................\":, \n"
|
|
|
|
" .,?........................................, \n"
|
|
|
|
" /...........................................,}\n"
|
|
|
|
" ./........................................,:`^`..}\n"
|
|
|
|
" ./.......................................,:\"...../\n"
|
|
|
|
" ?.....__..................................:`...../\n"
|
|
|
|
" /__.(...\"~-,_...........................,:`....../\n"
|
|
|
|
" /(_....\"~,_....\"~,_.....................,:`...._/ \n"
|
|
|
|
" {.._$;_....\"=,_.....\"-,_......,.-~-,},.~\";/....} \n"
|
|
|
|
" ((...*~_......\"=-._...\";,,./`........../\"..../ \n"
|
|
|
|
" ,,,___.`~,......\"~.,....................`......}....../ \n"
|
|
|
|
"............(....`=-,,...`.........................(...;_,,-\" \n"
|
|
|
|
"............/.`~,......`-.................................../ \n"
|
|
|
|
".............`~.*-,.....................................|,./...,__ \n"
|
|
|
|
",,_..........}.>-._...................................|.......`=~-, \n"
|
|
|
|
".....`=~-,__......`,................................. \n"
|
|
|
|
"...................`=~-,,.,........................... \n"
|
|
|
|
".........................`:,,..........................`\n"
|
|
|
|
"...........................`=-,...............,%%`>--==`` \n"
|
|
|
|
".................................._.........._,-%%...` \n"
|
|
|
|
"...................................,\n");
|
2020-04-10 03:19:33 +00:00
|
|
|
/* clang-format on */
|
2018-12-08 05:18:42 +00:00
|
|
|
}
|
2015-06-10 02:40:03 +00:00
|
|
|
|
2021-06-30 18:20:45 +00:00
|
|
|
static void ShowHelp(const std::string& toolName) {
|
2018-12-08 05:18:42 +00:00
|
|
|
/* Select tool's help-text streamer */
|
2019-08-20 02:52:33 +00:00
|
|
|
HelpOutput::HelpFunc helpFunc = nullptr;
|
2021-06-30 18:20:45 +00:00
|
|
|
if (toolName == "init")
|
2018-12-08 05:18:42 +00:00
|
|
|
helpFunc = ToolInit::Help;
|
2021-06-30 18:20:45 +00:00
|
|
|
else if (toolName == "spec")
|
2018-12-08 05:18:42 +00:00
|
|
|
helpFunc = ToolSpec::Help;
|
2021-06-30 18:20:45 +00:00
|
|
|
else if (toolName == "extract")
|
2018-12-08 05:18:42 +00:00
|
|
|
helpFunc = ToolExtract::Help;
|
2021-06-30 18:20:45 +00:00
|
|
|
else if (toolName == "cook")
|
2018-12-08 05:18:42 +00:00
|
|
|
helpFunc = ToolCook::Help;
|
2021-06-30 18:20:45 +00:00
|
|
|
else if (toolName == "package" || toolName == "pack")
|
2018-12-08 05:18:42 +00:00
|
|
|
helpFunc = ToolPackage::Help;
|
2021-06-30 18:20:45 +00:00
|
|
|
else if (toolName == "help")
|
2018-12-08 05:18:42 +00:00
|
|
|
helpFunc = ToolHelp::Help;
|
|
|
|
else {
|
2021-06-30 18:20:45 +00:00
|
|
|
LogModule.report(logvisor::Error, FMT_STRING("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
|
|
|
|
2021-06-30 18:20:45 +00:00
|
|
|
std::string_view toolName() const override { return "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
|
|
|
};
|