metaforce/hecl/driver/ToolHelp.hpp

81 lines
3.1 KiB
C++
Raw Permalink Normal View History

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:
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
~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(
" ___________ \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
static void ShowHelp(const std::string& toolName) {
2018-12-08 05:18:42 +00:00
/* Select tool's help-text streamer */
HelpOutput::HelpFunc helpFunc = nullptr;
if (toolName == "init")
2018-12-08 05:18:42 +00:00
helpFunc = ToolInit::Help;
else if (toolName == "spec")
2018-12-08 05:18:42 +00:00
helpFunc = ToolSpec::Help;
else if (toolName == "extract")
2018-12-08 05:18:42 +00:00
helpFunc = ToolExtract::Help;
else if (toolName == "cook")
2018-12-08 05:18:42 +00:00
helpFunc = ToolCook::Help;
else if (toolName == "package" || toolName == "pack")
2018-12-08 05:18:42 +00:00
helpFunc = ToolPackage::Help;
else if (toolName == "help")
2018-12-08 05:18:42 +00:00
helpFunc = ToolHelp::Help;
else {
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
std::string_view toolName() const override { return "help"sv; }
2015-06-10 02:40:03 +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
};