mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-20 08:05:45 +00:00
Change ZCG cpp to be able to handle multiple tasks
This commit is contained in:
parent
22b95e337a
commit
21440daf27
@ -45,8 +45,8 @@ class ZoneCodeGenerator::Impl
|
||||
|
||||
void PrintData() const
|
||||
{
|
||||
PrettyPrinter prettyPrinter;
|
||||
prettyPrinter.Print(m_repository.get());
|
||||
const PrettyPrinter prettyPrinter(std::cout, m_repository.get());
|
||||
prettyPrinter.PrintAll();
|
||||
}
|
||||
|
||||
bool GenerateCode()
|
||||
@ -73,20 +73,19 @@ public:
|
||||
|
||||
if (!ReadHeaderData() || !ReadCommandsData())
|
||||
return 1;
|
||||
|
||||
switch(m_args.m_task)
|
||||
|
||||
if(m_args.ShouldPrint())
|
||||
{
|
||||
case ZoneCodeGeneratorArguments::ProcessingTask::PRINT_DATA:
|
||||
PrintData();
|
||||
return 0;
|
||||
|
||||
case ZoneCodeGeneratorArguments::ProcessingTask::GENERATE_CODE:
|
||||
return GenerateCode() ? 0 : 1;
|
||||
|
||||
default:
|
||||
std::cout << "Unknown task: " << static_cast<int>(m_args.m_task) << std::endl;
|
||||
return 2;
|
||||
}
|
||||
|
||||
if(m_args.ShouldGenerate())
|
||||
{
|
||||
if (!GenerateCode())
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -94,10 +94,10 @@ ZoneCodeGeneratorArguments::GenerationTask::GenerationTask(std::string assetName
|
||||
}
|
||||
|
||||
ZoneCodeGeneratorArguments::ZoneCodeGeneratorArguments()
|
||||
: m_argument_parser(COMMAND_LINE_OPTIONS, _countof(COMMAND_LINE_OPTIONS))
|
||||
: m_argument_parser(COMMAND_LINE_OPTIONS, _countof(COMMAND_LINE_OPTIONS)),
|
||||
m_task_flags(0)
|
||||
{
|
||||
m_verbose = false;
|
||||
m_task = ProcessingTask::GENERATE_CODE;
|
||||
}
|
||||
|
||||
void ZoneCodeGeneratorArguments::PrintUsage()
|
||||
@ -132,7 +132,7 @@ bool ZoneCodeGeneratorArguments::Parse(const int argc, const char** argv)
|
||||
|
||||
// -p; --print
|
||||
if (m_argument_parser.IsOptionSpecified(OPTION_PRINT))
|
||||
m_task = ProcessingTask::PRINT_DATA;
|
||||
m_task_flags |= FLAG_TASK_PRINT;
|
||||
|
||||
// -o; --output
|
||||
if (m_argument_parser.IsOptionSpecified(OPTION_OUTPUT_FOLDER))
|
||||
@ -164,25 +164,30 @@ bool ZoneCodeGeneratorArguments::Parse(const int argc, const char** argv)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_task == ProcessingTask::GENERATE_CODE)
|
||||
if (m_argument_parser.IsOptionSpecified(OPTION_GENERATE))
|
||||
{
|
||||
if (!m_argument_parser.IsOptionSpecified(OPTION_GENERATE))
|
||||
{
|
||||
std::cout << "A generate parameter needs to be specified when generating code" << std::endl;
|
||||
PrintUsage();
|
||||
return false;
|
||||
}
|
||||
|
||||
m_task_flags |= FLAG_TASK_GENERATE;
|
||||
const auto generateParameterValues = m_argument_parser.GetParametersForOption(OPTION_GENERATE);
|
||||
for (auto i = 0u; i < generateParameterValues.size(); i+=2)
|
||||
for (auto i = 0u; i < generateParameterValues.size(); i += 2)
|
||||
m_generation_tasks.emplace_back(generateParameterValues[i], generateParameterValues[i + 1]);
|
||||
}
|
||||
else if (m_argument_parser.IsOptionSpecified(OPTION_GENERATE))
|
||||
|
||||
if (m_task_flags == 0)
|
||||
{
|
||||
std::cout << "Cannot specify generate parameter when not generating code" << std::endl;
|
||||
std::cout << "There was no output task specified." << std::endl;
|
||||
PrintUsage();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ZoneCodeGeneratorArguments::ShouldGenerate() const
|
||||
{
|
||||
return m_task_flags & FLAG_TASK_GENERATE;
|
||||
}
|
||||
|
||||
bool ZoneCodeGeneratorArguments::ShouldPrint() const
|
||||
{
|
||||
return m_task_flags & FLAG_TASK_PRINT;
|
||||
}
|
||||
|
@ -1,4 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "Utils/ClassUtils.h"
|
||||
#include "Utils/Arguments/ArgumentParser.h"
|
||||
|
||||
#include <vector>
|
||||
@ -13,11 +15,8 @@ class ZoneCodeGeneratorArguments
|
||||
static void PrintUsage();
|
||||
|
||||
public:
|
||||
enum class ProcessingTask
|
||||
{
|
||||
GENERATE_CODE,
|
||||
PRINT_DATA
|
||||
};
|
||||
static constexpr unsigned FLAG_TASK_GENERATE = 1 << 0;
|
||||
static constexpr unsigned FLAG_TASK_PRINT = 1 << 1;
|
||||
|
||||
class GenerationTask
|
||||
{
|
||||
@ -35,10 +34,13 @@ public:
|
||||
std::vector<std::string> m_command_paths;
|
||||
std::string m_output_directory;
|
||||
|
||||
ProcessingTask m_task;
|
||||
unsigned m_task_flags;
|
||||
std::vector<GenerationTask> m_generation_tasks;
|
||||
|
||||
ZoneCodeGeneratorArguments();
|
||||
|
||||
bool Parse(int argc, const char** argv);
|
||||
|
||||
_NODISCARD bool ShouldGenerate() const;
|
||||
_NODISCARD bool ShouldPrint() const;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user