metaforce/hecl/driver/ToolSpec.hpp

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