metaforce/hecl/driver/ToolSpec.hpp

155 lines
4.5 KiB
C++
Raw Normal View History

2015-06-10 02:40:03 +00:00
#ifndef CTOOL_SPEC
#define CTOOL_SPEC
#include "ToolBase.hpp"
#include <stdio.h>
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)
throw HECL::Exception(_S("hecl spec must be ran within a project directory"));
const auto& specs = info.project->getDataSpecs();
HECL::SystemString firstArg = info.args[0];
HECL::ToLower(firstArg);
static const HECL::SystemString enable(_S("enable"));
static const HECL::SystemString disable(_S("disable"));
if (!firstArg.compare(enable))
mode = MENABLE;
else if (!firstArg.compare(disable))
mode = MDISABLE;
else
return;
if (info.args.size() < 2)
throw HECL::Exception(_S("Speclist argument required"));
for (auto it = info.args.begin()+1;
it != info.args.end();
++it)
{
bool found = false;
for (auto& spec : specs)
{
2015-07-01 23:53:05 +00:00
if (!spec.first.m_name.compare(*it))
2015-06-11 04:55:06 +00:00
{
found = true;
break;
}
}
if (!found)
throw HECL::Exception(_S("'") + *it + _S("' is not found in the dataspec registry"));
}
2015-06-10 02:40:03 +00:00
}
static void Help(HelpOutput& help)
{
help.secHead(_S("NAME"));
help.beginWrap();
help.wrap(_S("hecl-spec - Configure target data options\n"));
help.endWrap();
help.secHead(_S("SYNOPSIS"));
help.beginWrap();
help.wrap(_S("hecl spec [enable|disable] [<specname>...]\n"));
help.endWrap();
help.secHead(_S("DESCRIPTION"));
help.beginWrap();
help.wrap(_S("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"));
help.endWrap();
help.secHead(_S("OPTIONS"));
help.optionHead(_S("<specname>..."), _S("DataSpec name(s)"));
help.beginWrap();
help.wrap(_S("Specifies platform-names to enable/disable"));
help.endWrap();
}
HECL::SystemString toolName() const {return _S("spec");}
int run()
{
2015-06-11 04:55:06 +00:00
if (!m_info.project)
{
2015-07-01 23:53:05 +00:00
for (const HECL::Database::DataSpecEntry* spec : HECL::Database::DATA_SPEC_REGISTRY)
2015-06-11 04:55:06 +00:00
{
if (XTERM_COLOR)
2015-07-01 23:53:05 +00:00
HECL::Printf(_S("" BOLD CYAN "%s" NORMAL "\n"), spec->m_name.c_str());
2015-06-11 04:55:06 +00:00
else
2015-07-01 23:53:05 +00:00
HECL::Printf(_S("%s\n"), spec->m_name.c_str());
HECL::Printf(_S(" %s\n"), spec->m_desc.c_str());
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)
2015-07-01 23:53:05 +00:00
HECL::Printf(_S("" BOLD CYAN "%s" NORMAL ""), spec.first.m_name.c_str());
2015-06-11 04:55:06 +00:00
else
2015-07-01 23:53:05 +00:00
HECL::Printf(_S("%s"), spec.first.m_name.c_str());
2015-06-11 04:55:06 +00:00
if (spec.second)
{
if (XTERM_COLOR)
HECL::Printf(_S(" " BOLD GREEN "[ENABLED]" NORMAL ""));
else
HECL::Printf(_S(" [ENABLED]"));
}
2015-07-01 23:53:05 +00:00
HECL::Printf(_S("\n %s\n"), spec.first.m_desc.c_str());
2015-06-11 04:55:06 +00:00
}
return 0;
}
std::vector<HECL::SystemString> opSpecs;
for (auto it = m_info.args.begin()+1;
it != m_info.args.end();
++it)
{
HECL::SystemString itName = *it;
HECL::ToLower(itName);
for (auto& spec : specs)
{
2015-07-01 23:53:05 +00:00
if (!spec.first.m_name.compare(itName))
2015-06-11 04:55:06 +00:00
{
2015-07-01 23:53:05 +00:00
opSpecs.push_back(spec.first.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;
}
};
#endif // CTOOL_SPEC