From 36cc8d306512cbb322d923fd6e88db7dbf28f11f Mon Sep 17 00:00:00 2001 From: Jan Date: Thu, 26 Sep 2019 21:43:49 +0200 Subject: [PATCH] Make use of ArgumentParser and UsageInformation Generator in unlink tool --- src/Unlinker/main.cpp | 73 +++++++++++++++++++++++++++++++-- src/ZoneLoading/ZoneLoading.cpp | 2 +- src/ZoneLoading/ZoneLoading.h | 2 +- 3 files changed, 71 insertions(+), 6 deletions(-) diff --git a/src/Unlinker/main.cpp b/src/Unlinker/main.cpp index aca64b69..1ee7830e 100644 --- a/src/Unlinker/main.cpp +++ b/src/Unlinker/main.cpp @@ -1,25 +1,90 @@ +#include #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") .WithLongName("minimal-zone") .WithDescription("Minimizes the size of the zone file output by only including assets that are not a dependency of another asset.") .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") .WithLongName("output-folder") .WithDescription("Specifies the output folder containing the contents of the unlinked zones. Defaults to ./%zoneName%") .WithParameter("outputFolderPath") .Build(); -CommandLineOption* commandLineOptions[] +const CommandLineOption* commandLineOptions[] { + optionHelp, optionMinimalZoneFile, + optionList, 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 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; } \ No newline at end of file diff --git a/src/ZoneLoading/ZoneLoading.cpp b/src/ZoneLoading/ZoneLoading.cpp index e4a83d06..c149b756 100644 --- a/src/ZoneLoading/ZoneLoading.cpp +++ b/src/ZoneLoading/ZoneLoading.cpp @@ -1,6 +1,6 @@ #include "ZoneLoading.h" -bool ZoneLoading::LoadZone(std::string& path) +bool ZoneLoading::LoadZone(const std::string& path) { return false; } \ No newline at end of file diff --git a/src/ZoneLoading/ZoneLoading.h b/src/ZoneLoading/ZoneLoading.h index d6f375ae..85e38cbd 100644 --- a/src/ZoneLoading/ZoneLoading.h +++ b/src/ZoneLoading/ZoneLoading.h @@ -4,5 +4,5 @@ class ZoneLoading { public: - static bool LoadZone(std::string& path); + static bool LoadZone(const std::string& path); };