OpenAssetTools/src/Decompiler/DecompilerArgs.cpp
2023-06-19 21:16:01 +02:00

69 lines
1.5 KiB
C++

#include "DecompilerArgs.h"
#include "Utils/Arguments/UsageInformation.h"
#include "Utils/FileUtils.h"
const CommandLineOption* const OPTION_HELP =
CommandLineOption::Builder::Create()
.WithShortName("?")
.WithLongName("help")
.WithDescription("Displays usage information.")
.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 COMMAND_LINE_OPTIONS[]
{
OPTION_HELP,
OPTION_VERBOSE
};
DecompilerArgs::DecompilerArgs()
: m_argument_parser(COMMAND_LINE_OPTIONS, std::extent_v<decltype(COMMAND_LINE_OPTIONS)>),
m_verbose(false)
{
}
void DecompilerArgs::PrintUsage()
{
UsageInformation usage("Decompiler.exe");
for (const auto* commandLineOption : COMMAND_LINE_OPTIONS)
{
usage.AddCommandLineOption(commandLineOption);
}
usage.Print();
}
void DecompilerArgs::SetVerbose(const bool isVerbose)
{
m_verbose = isVerbose;
}
bool DecompilerArgs::ParseArgs(const int argc, const char** argv)
{
if (!m_argument_parser.ParseArguments(argc - 1, &argv[1]))
{
PrintUsage();
return false;
}
// Check if the user requested help
if (m_argument_parser.IsOptionSpecified(OPTION_HELP))
{
PrintUsage();
return false;
}
// -v; --verbose
SetVerbose(m_argument_parser.IsOptionSpecified(OPTION_VERBOSE));
return true;
}