2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2025-10-19 04:55:19 +00:00

chore: add ModMan args

This commit is contained in:
Jan Laupetin
2025-10-11 14:15:04 +01:00
parent 4911cfa4c6
commit 2037cf3258
3 changed files with 138 additions and 1 deletions

105
src/ModMan/ModManArgs.cpp Normal file
View File

@@ -0,0 +1,105 @@
#include "ModManArgs.h"
#include "GitVersion.h"
#include "Utils/Arguments/UsageInformation.h"
#include "Utils/Logging/Log.h"
#include <format>
#include <type_traits>
namespace
{
// clang-format off
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();
const CommandLineOption* const OPTION_NO_COLOR =
CommandLineOption::Builder::Create()
.WithLongName("no-color")
.WithDescription("Disables colored terminal output.")
.Build();
// clang-format on
const CommandLineOption* const COMMAND_LINE_OPTIONS[]{
OPTION_HELP,
OPTION_VERSION,
OPTION_VERBOSE,
OPTION_NO_COLOR,
};
} // namespace
ModManArgs::ModManArgs()
: m_argument_parser(COMMAND_LINE_OPTIONS, std::extent_v<decltype(COMMAND_LINE_OPTIONS)>)
{
}
void ModManArgs::PrintUsage() const
{
UsageInformation usage(m_argument_parser.GetExecutableName());
for (const auto* commandLineOption : COMMAND_LINE_OPTIONS)
{
usage.AddCommandLineOption(commandLineOption);
}
usage.Print();
}
void ModManArgs::PrintVersion()
{
con::info("OpenAssetTools ModMan {}", GIT_VERSION);
}
bool ModManArgs::ParseArgs(const int argc, const char** argv, bool& shouldContinue)
{
shouldContinue = true;
if (!m_argument_parser.ParseArguments(argc, argv))
{
PrintUsage();
return false;
}
// Check if the user requested help
if (m_argument_parser.IsOptionSpecified(OPTION_HELP))
{
PrintUsage();
shouldContinue = false;
return true;
}
// Check if the user wants to see the version
if (m_argument_parser.IsOptionSpecified(OPTION_VERSION))
{
PrintVersion();
shouldContinue = false;
return true;
}
// -v; --verbose
if (m_argument_parser.IsOptionSpecified(OPTION_VERBOSE))
con::globalLogLevel = con::LogLevel::DEBUG;
else
con::globalLogLevel = con::LogLevel::INFO;
// --no-color
con::globalUseColor = !m_argument_parser.IsOptionSpecified(OPTION_NO_COLOR);
return true;
}

19
src/ModMan/ModManArgs.h Normal file
View File

@@ -0,0 +1,19 @@
#pragma once
#include "Utils/Arguments/ArgumentParser.h"
class ModManArgs
{
public:
ModManArgs();
bool ParseArgs(int argc, const char** argv, bool& shouldContinue);
private:
/**
* \brief Prints a command line usage help text for the ModMan tool to stdout.
*/
void PrintUsage() const;
static void PrintVersion();
ArgumentParser m_argument_parser;
};

View File

@@ -1,5 +1,6 @@
#include "Context/ModManContext.h"
#include "GitVersion.h"
#include "ModManArgs.h"
#include "Web/Binds/Binds.h"
#include "Web/Platform/AssetHandler.h"
#include "Web/UiCommunication.h"
@@ -94,9 +95,13 @@ namespace
} // namespace
#ifdef _WIN32
#define MODMAN_ARGC __argc
#define MODMAN_ARGV const_cast<const char**>(__argv)
int WINAPI WinMain(HINSTANCE /*hInst*/, HINSTANCE /*hPrevInst*/, LPSTR /*lpCmdLine*/, int /*nCmdShow*/)
#else
int main()
#define MODMAN_ARGC argc
#define MODMAN_ARGV argv
int main(int argc, const char** argv)
#endif
{
#ifdef _WIN32
@@ -114,6 +119,14 @@ int main()
}
#endif
ModManArgs args;
auto shouldContinue = true;
if (!args.ParseArgs(MODMAN_ARGC, MODMAN_ARGV, shouldContinue))
return false;
if (!shouldContinue)
return true;
con::info("Starting ModMan " GIT_VERSION);
ModManContext::Get().Startup();