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
No known key found for this signature in database
GPG Key ID: 44B581F78FF5C57C
12 changed files with 136 additions and 17 deletions

View File

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

View File

@ -1,11 +1,13 @@
#include "LinkerArgs.h" #include "LinkerArgs.h"
#include "GitVersion.h"
#include "ObjLoading.h" #include "ObjLoading.h"
#include "ObjWriting.h" #include "ObjWriting.h"
#include "Utils/Arguments/UsageInformation.h" #include "Utils/Arguments/UsageInformation.h"
#include "Utils/FileUtils.h" #include "Utils/FileUtils.h"
#include <filesystem> #include <filesystem>
#include <iostream>
#include <regex> #include <regex>
#include <type_traits> #include <type_traits>
@ -19,6 +21,12 @@ const CommandLineOption* const OPTION_HELP =
.WithDescription("Displays usage information.") .WithDescription("Displays usage information.")
.Build(); .Build();
const CommandLineOption* const OPTION_VERSION =
CommandLineOption::Builder::Create()
.WithLongName("version")
.WithDescription("Prints the application version.")
.Build();
const CommandLineOption* const OPTION_VERBOSE = const CommandLineOption* const OPTION_VERBOSE =
CommandLineOption::Builder::Create() CommandLineOption::Builder::Create()
.WithShortName("v") .WithShortName("v")
@ -88,6 +96,7 @@ const CommandLineOption* const OPTION_MENU_NO_OPTIMIZATION =
const CommandLineOption* const COMMAND_LINE_OPTIONS[]{ const CommandLineOption* const COMMAND_LINE_OPTIONS[]{
OPTION_HELP, OPTION_HELP,
OPTION_VERSION,
OPTION_VERBOSE, OPTION_VERBOSE,
OPTION_BASE_FOLDER, OPTION_BASE_FOLDER,
OPTION_OUTPUT_FOLDER, OPTION_OUTPUT_FOLDER,
@ -100,7 +109,7 @@ const CommandLineOption* const COMMAND_LINE_OPTIONS[]{
}; };
LinkerArgs::LinkerArgs() LinkerArgs::LinkerArgs()
: m_argument_parser(COMMAND_LINE_OPTIONS, std::extent<decltype(COMMAND_LINE_OPTIONS)>::value), : m_argument_parser(COMMAND_LINE_OPTIONS, std::extent_v<decltype(COMMAND_LINE_OPTIONS)>),
m_base_pattern(R"(\?base\?)"), m_base_pattern(R"(\?base\?)"),
m_game_pattern(R"(\?game\?)"), m_game_pattern(R"(\?game\?)"),
m_project_pattern(R"(\?project\?)"), m_project_pattern(R"(\?project\?)"),
@ -125,6 +134,11 @@ void LinkerArgs::PrintUsage()
usage.Print(); usage.Print();
} }
void LinkerArgs::PrintVersion()
{
std::cout << "OpenAssetTools Linker " << std::string(GIT_VERSION) << "\n";
}
void LinkerArgs::SetVerbose(const bool isVerbose) void LinkerArgs::SetVerbose(const bool isVerbose)
{ {
m_verbose = isVerbose; m_verbose = isVerbose;
@ -198,8 +212,9 @@ std::set<std::string> LinkerArgs::GetSearchPathsForProject(const std::set<std::s
return out; return out;
} }
bool LinkerArgs::ParseArgs(const int argc, const char** argv) bool LinkerArgs::ParseArgs(const int argc, const char** argv, bool& shouldContinue)
{ {
shouldContinue = true;
if (!m_argument_parser.ParseArguments(argc - 1, &argv[1])) if (!m_argument_parser.ParseArguments(argc - 1, &argv[1]))
{ {
PrintUsage(); PrintUsage();
@ -213,6 +228,14 @@ bool LinkerArgs::ParseArgs(const int argc, const char** argv)
return false; return false;
} }
// Check if the user wants to see the version
if (m_argument_parser.IsOptionSpecified(OPTION_VERSION))
{
PrintVersion();
shouldContinue = false;
return true;
}
m_project_specifiers_to_build = m_argument_parser.GetArguments(); m_project_specifiers_to_build = m_argument_parser.GetArguments();
if (m_project_specifiers_to_build.empty()) if (m_project_specifiers_to_build.empty())
{ {

View File

@ -31,6 +31,7 @@ private:
* \brief Prints a command line usage help text for the Linker tool to stdout. * \brief Prints a command line usage help text for the Linker tool to stdout.
*/ */
static void PrintUsage(); static void PrintUsage();
static void PrintVersion();
void SetVerbose(bool isVerbose); void SetVerbose(bool isVerbose);
@ -56,7 +57,7 @@ public:
bool m_verbose; bool m_verbose;
LinkerArgs(); LinkerArgs();
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 project. * \brief Converts the output path specified by command line arguments to a path applies for the specified project.

View File

@ -45,9 +45,13 @@ public:
int Run(const int argc, const char** argv) int Run(const int argc, const char** argv)
{ {
if (!m_args.Parse(argc, argv)) auto shouldContinue = true;
if (!m_args.ParseArgs(argc, argv, shouldContinue))
return 1; return 1;
if (!shouldContinue)
return 0;
if (!m_args.m_build_log_file.empty()) if (!m_args.m_build_log_file.empty())
{ {
fs::path p = fs::path(m_args.m_build_log_file).parent_path(); fs::path p = fs::path(m_args.m_build_log_file).parent_path();

View File

@ -1,11 +1,18 @@
#include "RawTemplaterArguments.h" #include "RawTemplaterArguments.h"
#include "GitVersion.h"
#include "Utils/Arguments/CommandLineOption.h" #include "Utils/Arguments/CommandLineOption.h"
#include "Utils/Arguments/UsageInformation.h" #include "Utils/Arguments/UsageInformation.h"
#include <iostream>
#include <type_traits>
const CommandLineOption* const OPTION_HELP = const CommandLineOption* const OPTION_HELP =
CommandLineOption::Builder::Create().WithShortName("?").WithLongName("help").WithDescription("Displays usage information.").Build(); CommandLineOption::Builder::Create().WithShortName("?").WithLongName("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 = const CommandLineOption* const OPTION_VERBOSE =
CommandLineOption::Builder::Create().WithShortName("v").WithLongName("verbose").WithDescription("Outputs a lot more and more detailed messages.").Build(); CommandLineOption::Builder::Create().WithShortName("v").WithLongName("verbose").WithDescription("Outputs a lot more and more detailed messages.").Build();
@ -30,7 +37,14 @@ const CommandLineOption* const OPTION_DEFINE = CommandLineOption::Builder::Creat
.Reusable() .Reusable()
.Build(); .Build();
const CommandLineOption* const COMMAND_LINE_OPTIONS[]{OPTION_HELP, OPTION_VERBOSE, OPTION_OUTPUT_FOLDER, OPTION_BUILD_LOG, OPTION_DEFINE}; const CommandLineOption* const COMMAND_LINE_OPTIONS[]{
OPTION_HELP,
OPTION_VERSION,
OPTION_VERBOSE,
OPTION_OUTPUT_FOLDER,
OPTION_BUILD_LOG,
OPTION_DEFINE,
};
RawTemplaterArguments::RawTemplaterArguments() RawTemplaterArguments::RawTemplaterArguments()
: m_argument_parser(COMMAND_LINE_OPTIONS, std::extent_v<decltype(COMMAND_LINE_OPTIONS)>), : m_argument_parser(COMMAND_LINE_OPTIONS, std::extent_v<decltype(COMMAND_LINE_OPTIONS)>),
@ -50,8 +64,14 @@ void RawTemplaterArguments::PrintUsage()
usage.Print(); usage.Print();
} }
bool RawTemplaterArguments::Parse(const int argc, const char** argv) void RawTemplaterArguments::PrintVersion()
{ {
std::cout << "OpenAssetTools RawTemplater " << std::string(GIT_VERSION) << "\n";
}
bool RawTemplaterArguments::ParseArgs(const int argc, const char** argv, bool& shouldContinue)
{
shouldContinue = true;
if (!m_argument_parser.ParseArguments(argc - 1, &argv[1])) if (!m_argument_parser.ParseArguments(argc - 1, &argv[1]))
{ {
PrintUsage(); PrintUsage();
@ -65,6 +85,14 @@ bool RawTemplaterArguments::Parse(const int argc, const char** argv)
return false; return false;
} }
// Check if the user wants to see the version
if (m_argument_parser.IsOptionSpecified(OPTION_VERSION))
{
PrintVersion();
shouldContinue = false;
return true;
}
m_input_files = m_argument_parser.GetArguments(); m_input_files = m_argument_parser.GetArguments();
if (m_input_files.empty()) if (m_input_files.empty())
{ {

View File

@ -14,6 +14,7 @@ class RawTemplaterArguments
* \brief Prints a command line usage help text for the RawTemplater tool to stdout. * \brief Prints a command line usage help text for the RawTemplater tool to stdout.
*/ */
static void PrintUsage(); static void PrintUsage();
static void PrintVersion();
public: public:
bool m_verbose; bool m_verbose;
@ -27,5 +28,5 @@ public:
RawTemplaterArguments(); RawTemplaterArguments();
bool Parse(int argc, const char** argv); bool ParseArgs(int argc, const char** argv, bool& shouldContinue);
}; };

View File

@ -429,9 +429,13 @@ public:
*/ */
bool Start(const int argc, const char** argv) 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; return false;
if (!shouldContinue)
return true;
if (!BuildSearchPaths()) if (!BuildSearchPaths())
return false; return false;

View File

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

View File

@ -21,6 +21,7 @@ private:
* \brief Prints a command line usage help text for the Unlinker tool to stdout. * \brief Prints a command line usage help text for the Unlinker tool to stdout.
*/ */
static void PrintUsage(); static void PrintUsage();
static void PrintVersion();
void SetVerbose(bool isVerbose); void SetVerbose(bool isVerbose);
bool SetImageDumpingMode(); bool SetImageDumpingMode();
@ -60,7 +61,7 @@ public:
bool m_verbose; bool m_verbose;
UnlinkerArgs(); 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. * \brief Converts the output path specified by command line arguments to a path applies for the specified zone.

View File

@ -64,9 +64,13 @@ public:
int Run(const int argc, const char** argv) int Run(const int argc, const char** argv)
{ {
if (!m_args.Parse(argc, argv)) auto shouldContinue = true;
if (!m_args.ParseArgs(argc, argv, shouldContinue))
return 1; return 1;
if (!shouldContinue)
return 0;
if (!ReadHeaderData() || !ReadCommandsData()) if (!ReadHeaderData() || !ReadCommandsData())
return 1; return 1;

View File

@ -1,5 +1,6 @@
#include "ZoneCodeGeneratorArguments.h" #include "ZoneCodeGeneratorArguments.h"
#include "GitVersion.h"
#include "Utils/Arguments/CommandLineOption.h" #include "Utils/Arguments/CommandLineOption.h"
#include "Utils/Arguments/UsageInformation.h" #include "Utils/Arguments/UsageInformation.h"
@ -9,6 +10,9 @@
const CommandLineOption* const OPTION_HELP = const CommandLineOption* const OPTION_HELP =
CommandLineOption::Builder::Create().WithShortName("?").WithLongName("help").WithDescription("Displays usage information.").Build(); CommandLineOption::Builder::Create().WithShortName("?").WithLongName("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 = const CommandLineOption* const OPTION_VERBOSE =
CommandLineOption::Builder::Create().WithShortName("v").WithLongName("verbose").WithDescription("Outputs a lot more and more detailed messages.").Build(); CommandLineOption::Builder::Create().WithShortName("v").WithLongName("verbose").WithDescription("Outputs a lot more and more detailed messages.").Build();
@ -70,7 +74,15 @@ const CommandLineOption* const OPTION_GENERATE =
.Build(); .Build();
const CommandLineOption* const COMMAND_LINE_OPTIONS[]{ const CommandLineOption* const COMMAND_LINE_OPTIONS[]{
OPTION_HELP, OPTION_VERBOSE, OPTION_HEADER, OPTION_COMMANDS_FILE, OPTION_OUTPUT_FOLDER, OPTION_PRINT, OPTION_GENERATE}; OPTION_HELP,
OPTION_VERSION,
OPTION_VERBOSE,
OPTION_HEADER,
OPTION_COMMANDS_FILE,
OPTION_OUTPUT_FOLDER,
OPTION_PRINT,
OPTION_GENERATE,
};
ZoneCodeGeneratorArguments::GenerationTask::GenerationTask() ZoneCodeGeneratorArguments::GenerationTask::GenerationTask()
: m_all_assets(false) : m_all_assets(false)
@ -91,7 +103,7 @@ ZoneCodeGeneratorArguments::GenerationTask::GenerationTask(std::string assetName
} }
ZoneCodeGeneratorArguments::ZoneCodeGeneratorArguments() ZoneCodeGeneratorArguments::ZoneCodeGeneratorArguments()
: m_argument_parser(COMMAND_LINE_OPTIONS, std::extent<decltype(COMMAND_LINE_OPTIONS)>::value), : m_argument_parser(COMMAND_LINE_OPTIONS, std::extent_v<decltype(COMMAND_LINE_OPTIONS)>),
m_task_flags(0) m_task_flags(0)
{ {
m_verbose = false; m_verbose = false;
@ -109,8 +121,14 @@ void ZoneCodeGeneratorArguments::PrintUsage()
usage.Print(); usage.Print();
} }
bool ZoneCodeGeneratorArguments::Parse(const int argc, const char** argv) void ZoneCodeGeneratorArguments::PrintVersion()
{ {
std::cout << "OpenAssetTools ZoneCodeGenerator " << std::string(GIT_VERSION) << "\n";
}
bool ZoneCodeGeneratorArguments::ParseArgs(const int argc, const char** argv, bool& shouldContinue)
{
shouldContinue = true;
if (!m_argument_parser.ParseArguments(argc - 1, &argv[1])) if (!m_argument_parser.ParseArguments(argc - 1, &argv[1]))
{ {
PrintUsage(); PrintUsage();
@ -124,6 +142,14 @@ bool ZoneCodeGeneratorArguments::Parse(const int argc, const char** argv)
return false; return false;
} }
// Check if the user wants to see the version
if (m_argument_parser.IsOptionSpecified(OPTION_VERSION))
{
PrintVersion();
shouldContinue = false;
return true;
}
// -v; --verbose // -v; --verbose
m_verbose = m_argument_parser.IsOptionSpecified(OPTION_VERBOSE); m_verbose = m_argument_parser.IsOptionSpecified(OPTION_VERBOSE);

View File

@ -13,6 +13,7 @@ class ZoneCodeGeneratorArguments
* \brief Prints a command line usage help text for the Unlinker tool to stdout. * \brief Prints a command line usage help text for the Unlinker tool to stdout.
*/ */
static void PrintUsage(); static void PrintUsage();
static void PrintVersion();
public: public:
static constexpr unsigned FLAG_TASK_GENERATE = 1 << 0; static constexpr unsigned FLAG_TASK_GENERATE = 1 << 0;
@ -40,8 +41,7 @@ public:
std::vector<GenerationTask> m_generation_tasks; std::vector<GenerationTask> m_generation_tasks;
ZoneCodeGeneratorArguments(); ZoneCodeGeneratorArguments();
bool ParseArgs(int argc, const char** argv, bool& shouldContinue);
bool Parse(int argc, const char** argv);
_NODISCARD bool ShouldGenerate() const; _NODISCARD bool ShouldGenerate() const;
_NODISCARD bool ShouldPrint() const; _NODISCARD bool ShouldPrint() const;