Make use of ArgumentParser and UsageInformation Generator in unlink tool

This commit is contained in:
Jan 2019-09-26 21:43:49 +02:00
parent c76352077a
commit 36cc8d3065
3 changed files with 71 additions and 6 deletions

View File

@ -1,25 +1,90 @@
#include <cstdlib>
#include "Utils/Arguments/ArgumentParser.h" #include "Utils/Arguments/ArgumentParser.h"
#include "Utils/Arguments/UsageInformation.h"
#include "ZoneLoading.h"
CommandLineOption* optionMinimalZoneFile = CommandLineOption::Builder::Create() const CommandLineOption* optionHelp = CommandLineOption::Builder::Create()
.WithShortName("?")
.WithLongName("help")
.WithDescription("Displays usage information.")
.Build();
const CommandLineOption* optionMinimalZoneFile = CommandLineOption::Builder::Create()
.WithShortName("min") .WithShortName("min")
.WithLongName("minimal-zone") .WithLongName("minimal-zone")
.WithDescription("Minimizes the size of the zone file output by only including assets that are not a dependency of another asset.") .WithDescription("Minimizes the size of the zone file output by only including assets that are not a dependency of another asset.")
.Build(); .Build();
CommandLineOption* optionOutputFolder = CommandLineOption::Builder::Create() const CommandLineOption* optionList = CommandLineOption::Builder::Create()
.WithShortName("l")
.WithLongName("list")
.WithDescription("Lists the contents of a zone instead of writing them to the disk.")
.Build();
const CommandLineOption* optionOutputFolder = CommandLineOption::Builder::Create()
.WithShortName("o") .WithShortName("o")
.WithLongName("output-folder") .WithLongName("output-folder")
.WithDescription("Specifies the output folder containing the contents of the unlinked zones. Defaults to ./%zoneName%") .WithDescription("Specifies the output folder containing the contents of the unlinked zones. Defaults to ./%zoneName%")
.WithParameter("outputFolderPath") .WithParameter("outputFolderPath")
.Build(); .Build();
CommandLineOption* commandLineOptions[] const CommandLineOption* commandLineOptions[]
{ {
optionHelp,
optionMinimalZoneFile, optionMinimalZoneFile,
optionList,
optionOutputFolder optionOutputFolder
}; };
int main(int argc, const char** argv) void PrintUsage()
{ {
UsageInformation usage("unlinker.exe");
for (auto commandLineOption : commandLineOptions)
{
usage.AddCommandLineOption(commandLineOption);
}
usage.AddArgument("pathToZone");
usage.SetVariableArguments(true);
usage.Print();
}
int main(const int argc, const char** argv)
{
ArgumentParser argumentParser(commandLineOptions, _countof(commandLineOptions));
if(!argumentParser.ParseArguments(argc, argv))
{
PrintUsage();
return 1;
}
if(argumentParser.IsOptionSpecified(optionHelp))
{
PrintUsage();
return 0;
}
const std::vector<std::string> arguments = argumentParser.GetArguments();
const size_t argCount = arguments.size();
if(argCount <= 1)
{
PrintUsage();
return 1;
}
for(unsigned argIndex = 1; argIndex < argCount; argIndex++)
{
const std::string& zonePath = arguments[argIndex];
if(!ZoneLoading::LoadZone(zonePath))
{
printf("Failed to load zone '%s'.\n", zonePath.c_str());
return 1;
}
}
return 0; return 0;
} }

View File

@ -1,6 +1,6 @@
#include "ZoneLoading.h" #include "ZoneLoading.h"
bool ZoneLoading::LoadZone(std::string& path) bool ZoneLoading::LoadZone(const std::string& path)
{ {
return false; return false;
} }

View File

@ -4,5 +4,5 @@
class ZoneLoading class ZoneLoading
{ {
public: public:
static bool LoadZone(std::string& path); static bool LoadZone(const std::string& path);
}; };