4#include <unordered_map>
7#define APP_EXTENSION ".exe"
9#define APP_EXTENSION ""
18 "\t--help, -h Show this help message\n"
19 "\t--version, -v Show version information\n"
20 "\t--config, -c Specify path to config file\n";
29 std::ifstream file(path);
32 throw std::runtime_error(
"Cannot open config file: " + path);
38 if (j.contains(
"window"))
40 const auto &w = j[
"window"];
41 if (w.contains(
"width"))
43 cfg.
width = w[
"width"];
45 if (w.contains(
"height"))
49 if (w.contains(
"frame_limit"))
53 if (w.contains(
"fullscreen"))
57 const auto &p = j[
"plugins"];
58 if (p.contains(
"audio"))
62 if (p.contains(
"network"))
66 if (p.contains(
"renderer"))
70 const auto &c = j[
"client"];
71 if (c.contains(
"host"))
75 if (c.contains(
"port"))
90 using ArgHandler = std::function<void(
const char *arg)>;
91 std::unordered_map<std::string_view, ArgHandler> handlers;
93 for (
const auto *
const opt : {
"-h",
"--help"})
95 handlers[opt] = [&config](
const char *)
101 for (
const auto *
const opt : {
"-v",
"--version"})
103 handlers[opt] = [&config](
const char *)
110 for (
const auto *
const opt : {
"-c",
"--config"})
112 handlers[opt] = [&config](
const char *arg)
116 throw std::runtime_error(
"Missing config file argument");
120 std::cout <<
"\tWidth: " << config.width <<
'\n'
121 <<
"\tHeight: " << config.height <<
'\n'
122 <<
"\tFrameLimit: " << config.frameLimit <<
"\n"
123 <<
"\tFullscreen: " << (config.fullscreen ?
"true" :
"false") <<
'\n';
127 const std::string_view key = argv[1];
128 const char *argValue = (argc > 2) ? argv[2] :
nullptr;
130 if (
const auto it = handlers.find(key); it != handlers.end())
132 it->second(argValue);
136 throw std::runtime_error(
"Unknown argument: " + std::string(key));
This file contains the Logger class.
static ArgsConfig ParseArgs(int argc, const char *const argv[])
static EnvConfig ParseEnv(const char *const env[])
static void log(const std::string &message, const LogLevel &logLevel)
This file contains the ArgsHandler class declaration.
static constexpr std::string_view VERSION_MESSAGE
static constexpr std::string_view HELP_MESSAGE
static ArgsConfig fromFile(const std::string &path)
std::string audio_lib_path
std::string network_lib_path
std::string renderer_lib_path