feat: add version command line arg to all executables

This commit is contained in:
Jan
2024-01-23 23:14:09 +01:00
parent 7919683748
commit 05437cfd7d
12 changed files with 136 additions and 17 deletions

View File

@ -429,9 +429,13 @@ public:
*/
bool Start(const int argc, const char** argv)
{
if (!m_args.ParseArgs(argc, argv))
auto shouldContinue = true;
if (!m_args.ParseArgs(argc, argv, shouldContinue))
return false;
if (!shouldContinue)
return true;
if (!BuildSearchPaths())
return false;

View File

@ -1,10 +1,12 @@
#include "UnlinkerArgs.h"
#include "GitVersion.h"
#include "ObjLoading.h"
#include "ObjWriting.h"
#include "Utils/Arguments/UsageInformation.h"
#include "Utils/FileUtils.h"
#include <iostream>
#include <regex>
#include <type_traits>
@ -16,6 +18,12 @@ const CommandLineOption* const OPTION_HELP =
.WithDescription("Displays usage information.")
.Build();
const CommandLineOption* const OPTION_VERSION =
CommandLineOption::Builder::Create()
.WithLongName("version")
.WithDescription("Prints the application version.")
.Build();
const CommandLineOption* const OPTION_VERBOSE =
CommandLineOption::Builder::Create()
.WithShortName("v")
@ -113,6 +121,7 @@ const CommandLineOption* const OPTION_LEGACY_MENUS =
const CommandLineOption* const COMMAND_LINE_OPTIONS[]{
OPTION_HELP,
OPTION_VERSION,
OPTION_VERBOSE,
OPTION_MINIMAL_ZONE_FILE,
OPTION_LOAD,
@ -155,6 +164,11 @@ void UnlinkerArgs::PrintUsage()
usage.Print();
}
void UnlinkerArgs::PrintVersion()
{
std::cout << "OpenAssetTools Unlinker " << std::string(GIT_VERSION) << "\n";
}
void UnlinkerArgs::SetVerbose(const bool isVerbose)
{
m_verbose = isVerbose;
@ -237,8 +251,9 @@ void UnlinkerArgs::ParseCommaSeparatedAssetTypeString(const std::string& input)
AddSpecifiedAssetType(std::string(lowerInput, currentPos, lowerInput.size() - currentPos));
}
bool UnlinkerArgs::ParseArgs(const int argc, const char** argv)
bool UnlinkerArgs::ParseArgs(const int argc, const char** argv, bool& shouldContinue)
{
shouldContinue = true;
if (!m_argument_parser.ParseArguments(argc - 1, &argv[1]))
{
PrintUsage();
@ -252,6 +267,14 @@ bool UnlinkerArgs::ParseArgs(const int argc, const char** argv)
return false;
}
// Check if the user wants to see the version
if (m_argument_parser.IsOptionSpecified(OPTION_VERSION))
{
PrintVersion();
shouldContinue = false;
return true;
}
m_zones_to_unlink = m_argument_parser.GetArguments();
const size_t zoneCount = m_zones_to_unlink.size();
if (zoneCount < 1)

View File

@ -21,6 +21,7 @@ private:
* \brief Prints a command line usage help text for the Unlinker tool to stdout.
*/
static void PrintUsage();
static void PrintVersion();
void SetVerbose(bool isVerbose);
bool SetImageDumpingMode();
@ -60,7 +61,7 @@ public:
bool m_verbose;
UnlinkerArgs();
bool ParseArgs(int argc, const char** argv);
bool ParseArgs(int argc, const char** argv, bool& shouldContinue);
/**
* \brief Converts the output path specified by command line arguments to a path applies for the specified zone.