metaforce/hecl/driver/ToolInit.hpp

89 lines
2.6 KiB
C++
Raw Normal View History

2015-06-10 02:40:03 +00:00
#ifndef CTOOL_INIT
#define CTOOL_INIT
#include "ToolBase.hpp"
2017-12-29 07:56:31 +00:00
#include <cstdio>
2015-06-10 02:40:03 +00:00
class ToolInit final : public ToolBase
{
2016-03-04 23:02:44 +00:00
const hecl::SystemString* m_dir = NULL;
2015-06-10 02:40:03 +00:00
public:
ToolInit(const ToolPassInfo& info)
: ToolBase(info)
{
2016-03-04 23:02:44 +00:00
hecl::Sstat theStat;
const hecl::SystemString* dir;
2015-06-10 02:40:03 +00:00
if (info.args.size())
dir = &info.args.front();
2015-06-11 09:41:10 +00:00
else
dir = &info.cwd;
2016-03-04 23:02:44 +00:00
if (hecl::Stat(dir->c_str(), &theStat))
2015-06-11 09:41:10 +00:00
{
2016-03-04 23:02:44 +00:00
hecl::MakeDir(dir->c_str());
if (hecl::Stat(dir->c_str(), &theStat))
{
2016-03-04 23:02:44 +00:00
LogModule.report(logvisor::Fatal, _S("unable to stat '%s'"), dir->c_str());
return;
}
2015-06-11 09:41:10 +00:00
}
if (!S_ISDIR(theStat.st_mode))
2015-06-10 02:40:03 +00:00
{
2016-03-04 23:02:44 +00:00
LogModule.report(logvisor::Fatal, _S("'%s' is not a directory"), dir->c_str());
2015-06-11 09:41:10 +00:00
return;
}
2015-06-10 02:40:03 +00:00
2016-03-04 23:02:44 +00:00
hecl::SystemString testPath = *dir + _S("/.hecl/beacon");
if (!hecl::Stat(testPath.c_str(), &theStat))
2015-06-11 09:41:10 +00:00
{
2016-03-04 23:02:44 +00:00
LogModule.report(logvisor::Fatal, _S("project already exists at '%s'"), dir->c_str());
2015-06-11 09:41:10 +00:00
return;
2015-06-10 02:40:03 +00:00
}
2015-06-11 09:41:10 +00:00
m_dir = dir;
2015-06-10 02:40:03 +00:00
}
int run()
{
2015-06-11 09:41:10 +00:00
if (!m_dir)
return -1;
2016-03-04 23:02:44 +00:00
size_t ErrorRef = logvisor::ErrorCount;
hecl::Database::Project proj((hecl::ProjectRootPath(*m_dir)));
if (logvisor::ErrorCount > ErrorRef)
2015-06-11 09:41:10 +00:00
return -1;
2016-03-04 23:02:44 +00:00
LogModule.report(logvisor::Info, _S("initialized project at '%s/.hecl'"), m_dir->c_str());
2015-06-10 02:40:03 +00:00
return 0;
}
static void Help(HelpOutput& help)
{
help.secHead(_S("NAME"));
help.beginWrap();
help.wrap(_S("hecl-init - Initialize a brand-new project database\n"));
help.endWrap();
help.secHead(_S("SYNOPSIS"));
help.beginWrap();
help.wrap(_S("hecl init [<dir>]\n"));
help.endWrap();
help.secHead(_S("DESCRIPTION"));
help.beginWrap();
help.wrap(_S("Creates a "));
help.wrapBold(_S(".hecl"));
2015-07-22 19:14:50 +00:00
help.wrap(_S(" directory within the selected directory with an initialized database index. ")
_S("This constitutes an empty HECL project, ready for making stuff!!\n"));
2015-06-10 02:40:03 +00:00
help.endWrap();
help.secHead(_S("OPTIONS"));
help.optionHead(_S("<dir>"), _S("group directory path"));
help.beginWrap();
help.wrap(_S("Directory to create new project database in. If not specified, current directory is used.\n"));
help.endWrap();
}
2016-03-04 23:02:44 +00:00
hecl::SystemString toolName() const {return _S("init");}
2015-06-10 02:40:03 +00:00
};
#endif // CTOOL_INIT