Skip to content

Commit

Permalink
FEXServer: Move over to MicroArgParser
Browse files Browse the repository at this point in the history
  • Loading branch information
Sonicadvance1 committed Sep 16, 2024
1 parent d938854 commit 317b76a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 23 deletions.
43 changes: 21 additions & 22 deletions Source/Tools/FEXServer/ArgumentLoader.cpp
Original file line number Diff line number Diff line change
@@ -1,37 +1,36 @@
// SPDX-License-Identifier: MIT
#include "ArgumentLoader.h"
#include "Common/cpp-optparse/OptionParser.h"
#include "Common/MicroArgParser.h"
#include <FEXCore/fextl/fmt.h>

#include "git_version.h"

#include <fmt/format.h>

namespace FEXServer::Config {
static fextl::string Version = "FEX-Emu (" GIT_DESCRIBE_STRING ") ";

FEXServerOptions Load(int argc, char** argv) {
FEXServerOptions FEXOptions {};
optparse::OptionParser Parser = optparse::OptionParser().version(Version);

Parser.add_option("-k", "--kill").action("store_true").set_default(false).help("Shutdown an already active FEXServer");

Parser.add_option("-f", "--foreground").action("store_true").set_default(false).help("Run this FEXServer in the foreground");

Parser.add_option("-p", "--persistent").action("store").type("int").set_default(0).set_optional_value(true).metavar("n").help("Make FEXServer persistent. Optional number of seconds");
static std::array<FEX::MicroArgParser::ParseMember, 6> Args = {{
{FEX::MicroArgParser::ParseMember::Type::Bool, "-k", "--kill", "Shutdown an already active FEXServer", "0"},
{FEX::MicroArgParser::ParseMember::Type::Bool, "-f", "--foreground", "Run this FEXServer in the foreground", "0"},
{FEX::MicroArgParser::ParseMember::Type::IntOptional, "-p", "--persistent", "Make FEXServer persistent. Optional number of seconds.", "0"},
{FEX::MicroArgParser::ParseMember::Type::Bool, "-w", "--wait", "Wait for the FEXServer to shutdown", "0"},
// Defaults
{FEX::MicroArgParser::ParseMember::Type::Bool, "-v", "--version", "show program's verison number and exit", "0"},
{FEX::MicroArgParser::ParseMember::Type::Bool, "-h", "--help", "show this help message and exit", "0"},
}};

FEX::MicroArgParser Parser(Args);
Parser.Version("FEX-Emu (" GIT_DESCRIBE_STRING ") ");
Parser.Parse(argc, argv);

Parser.add_option("-w", "--wait").action("store_true").set_default(false).help("Wait for the FEXServer to shutdown");

Parser.add_option("-v").action("version").help("Version string");

optparse::Values Options = Parser.parse_args(argc, argv);

FEXOptions.Kill = Options.get("kill");
FEXOptions.Foreground = Options.get("foreground");
FEXOptions.Wait = Options.get("wait");
FEXServerOptions FEXOptions {};
FEXOptions.Kill = Parser.Get<bool>("-k");
FEXOptions.Foreground = Parser.Get<bool>("-f");
FEXOptions.Wait = Parser.Get<bool>("-w");
if (FEXOptions.Wait) {
FEXOptions.Foreground = true;
}
FEXOptions.PersistentTimeout = Options.get("persistent");

FEXOptions.PersistentTimeout = Parser.Get<uint32_t>("-p");

return FEXOptions;
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Tools/FEXServer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ target_include_directories(${NAME} PRIVATE
${CMAKE_BINARY_DIR}/generated
${CMAKE_SOURCE_DIR}/Source/)

target_link_libraries(${NAME} PRIVATE FEXCore Common cpp-optparse ${PTHREAD_LIB})
target_link_libraries(${NAME} PRIVATE FEXCore Common ${PTHREAD_LIB})

if (CMAKE_BUILD_TYPE MATCHES "RELEASE")
target_link_options(${NAME}
Expand Down

0 comments on commit 317b76a

Please sign in to comment.