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

@ -45,9 +45,13 @@ public:
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;
if (!shouldContinue)
return 0;
if (!m_args.m_build_log_file.empty())
{
fs::path p = fs::path(m_args.m_build_log_file).parent_path();

View File

@ -1,11 +1,18 @@
#include "RawTemplaterArguments.h"
#include "GitVersion.h"
#include "Utils/Arguments/CommandLineOption.h"
#include "Utils/Arguments/UsageInformation.h"
#include <iostream>
#include <type_traits>
const CommandLineOption* const OPTION_HELP =
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 =
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()
.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()
: m_argument_parser(COMMAND_LINE_OPTIONS, std::extent_v<decltype(COMMAND_LINE_OPTIONS)>),
@ -50,8 +64,14 @@ void RawTemplaterArguments::PrintUsage()
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]))
{
PrintUsage();
@ -65,6 +85,14 @@ bool RawTemplaterArguments::Parse(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_input_files = m_argument_parser.GetArguments();
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.
*/
static void PrintUsage();
static void PrintVersion();
public:
bool m_verbose;
@ -27,5 +28,5 @@ public:
RawTemplaterArguments();
bool Parse(int argc, const char** argv);
bool ParseArgs(int argc, const char** argv, bool& shouldContinue);
};