metaforce/hecl/driver/ToolSpec.hpp

132 lines
3.7 KiB
C++
Raw 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-11 04:55:06 +00:00
#include <map>
2015-06-10 02:40:03 +00:00
2018-12-08 05:18:42 +00:00
class ToolSpec final : public ToolBase {
enum Mode { MLIST = 0, MENABLE, MDISABLE } mode = MLIST;
2015-06-10 02:40:03 +00:00
public:
explicit ToolSpec(const ToolPassInfo& info) : ToolBase(info) {
2018-12-08 05:18:42 +00:00
if (info.args.empty())
return;
if (!info.project)
2020-04-11 22:48:11 +00:00
LogModule.report(logvisor::Fatal, FMT_STRING("hecl spec must be ran within a project directory"));
2018-12-08 05:18:42 +00:00
const auto& specs = info.project->getDataSpecs();
std::string firstArg = info.args.front();
2018-12-08 05:18:42 +00:00
hecl::ToLower(firstArg);
if (firstArg == "enable")
2018-12-08 05:18:42 +00:00
mode = MENABLE;
else if (firstArg == "disable")
2018-12-08 05:18:42 +00:00
mode = MDISABLE;
else
return;
if (info.args.size() < 2)
2020-04-11 22:48:11 +00:00
LogModule.report(logvisor::Fatal, FMT_STRING("Speclist argument required"));
2018-12-08 05:18:42 +00:00
auto it = info.args.begin();
++it;
for (; it != info.args.end(); ++it) {
bool found = false;
for (auto& spec : specs) {
if (!it->compare(spec.spec.m_name)) {
found = true;
break;
2015-06-11 04:55:06 +00:00
}
2018-12-08 05:18:42 +00:00
}
if (!found)
LogModule.report(logvisor::Fatal, FMT_STRING("'{}' is not found in the dataspec registry"), *it);
2015-06-10 02:40:03 +00:00
}
2018-12-08 05:18:42 +00:00
}
static void Help(HelpOutput& help) {
help.secHead("NAME");
2018-12-08 05:18:42 +00:00
help.beginWrap();
help.wrap("hecl-spec - Configure target data options\n");
2018-12-08 05:18:42 +00:00
help.endWrap();
help.secHead("SYNOPSIS");
2018-12-08 05:18:42 +00:00
help.beginWrap();
help.wrap("hecl spec [enable|disable] [<specname>...]\n");
2018-12-08 05:18:42 +00:00
help.endWrap();
help.secHead("DESCRIPTION");
2018-12-08 05:18:42 +00:00
help.beginWrap();
help.wrap(
"This command configures the HECL project with the user's preferred target DataSpecs.\n\n"
"Providing enable/disable argument will bulk-set the enable status of the provided spec(s)"
"list. If enable/disable is not provided, a list of supported DataSpecs is printed.\n\n");
2018-12-08 05:18:42 +00:00
help.endWrap();
help.secHead("OPTIONS");
help.optionHead("<specname>...", "DataSpec name(s)");
2018-12-08 05:18:42 +00:00
help.beginWrap();
help.wrap("Specifies platform-names to enable/disable");
2018-12-08 05:18:42 +00:00
help.endWrap();
}
std::string_view toolName() const override { return "spec"sv; }
2018-12-08 05:18:42 +00:00
int run() override {
2018-12-08 05:18:42 +00:00
if (!m_info.project) {
for (const hecl::Database::DataSpecEntry* spec : hecl::Database::DATA_SPEC_REGISTRY) {
if (XTERM_COLOR)
fmt::print(FMT_STRING("" BOLD CYAN "{}" NORMAL "\n"), spec->m_name);
2018-12-08 05:18:42 +00:00
else
fmt::print(FMT_STRING("{}\n"), spec->m_name);
fmt::print(FMT_STRING(" {}\n"), spec->m_desc);
2018-12-08 05:18:42 +00:00
}
return 0;
2015-06-10 02:40:03 +00:00
}
2018-12-08 05:18:42 +00:00
const auto& specs = m_info.project->getDataSpecs();
if (mode == MLIST) {
for (auto& spec : specs) {
if (XTERM_COLOR)
fmt::print(FMT_STRING("" BOLD CYAN "{}" NORMAL ""), spec.spec.m_name);
2018-12-08 05:18:42 +00:00
else
fmt::print(FMT_STRING("{}"), spec.spec.m_name);
2018-12-08 05:18:42 +00:00
if (spec.active) {
if (XTERM_COLOR)
fmt::print(FMT_STRING(" " BOLD GREEN "[ENABLED]" NORMAL ""));
2018-12-08 05:18:42 +00:00
else
fmt::print(FMT_STRING(" [ENABLED]"));
2015-06-11 04:55:06 +00:00
}
fmt::print(FMT_STRING("\n {}\n"), spec.spec.m_desc);
2018-12-08 05:18:42 +00:00
}
return 0;
}
2015-06-11 04:55:06 +00:00
std::vector<std::string> opSpecs;
2018-12-08 05:18:42 +00:00
auto it = m_info.args.begin();
++it;
for (; it != m_info.args.end(); ++it) {
std::string itName = *it;
2018-12-08 05:18:42 +00:00
hecl::ToLower(itName);
for (auto& spec : specs) {
std::string compName(spec.spec.m_name);
2018-12-08 05:18:42 +00:00
hecl::ToLower(compName);
2019-10-01 07:23:35 +00:00
if (itName == compName) {
2018-12-08 05:18:42 +00:00
opSpecs.emplace_back(spec.spec.m_name);
break;
2015-06-11 04:55:06 +00:00
}
2018-12-08 05:18:42 +00:00
}
}
2015-06-11 04:55:06 +00:00
2018-12-08 05:18:42 +00:00
if (opSpecs.size()) {
if (mode == MENABLE)
m_info.project->enableDataSpecs(opSpecs);
else if (mode == MDISABLE)
m_info.project->disableDataSpecs(opSpecs);
2015-06-10 02:40:03 +00:00
}
2018-12-08 05:18:42 +00:00
return 0;
}
};