5Args::Args(
int argc,
char** argv) { parseArgs(argc, argv); }
13 if (
result == ParseResult::Success ||
result == ParseResult::HelpRequested) {
21void Args::parseArgs(
int argc,
char** argv)
24 setError(
"No arguments provided", argv[0]);
28 for (
int i = 1; i < argc; ++i) {
29 std::string arg = argv[i];
31 if (arg ==
"--help") {
33 result = ParseResult::HelpRequested;
35 }
else if (arg ==
"--headless") {
37 }
else if (arg ==
"--dev") {
39 setError(
"--dev requires a value (true or false)", argv[0]);
42 std::string val = argv[++i];
45 else if (val ==
"false")
48 setError(
"--dev value must be true or false", argv[0]);
51 }
else if (arg ==
"--language") {
53 setError(
"--language requires a value (english or french)", argv[0]);
56 std::string lang = argv[++i];
59 else if (lang ==
"english")
62 setError(
"Unknown language: " + lang +
" (use english or french)", argv[0]);
65 }
else if (arg ==
"-p") {
67 setError(
"-p requires a port number", argv[0]);
73 setError(
"Port must be between 1 and 65535", argv[0]);
77 }
catch (
const std::exception&) {
78 setError(
"Invalid port number: " + std::string(argv[i + 1]), argv[0]);
81 }
else if (arg ==
"-h") {
83 setError(
"-h requires a machine name", argv[0]);
86 config.machine = argv[i + 1];
89 setError(
"Unknown argument: " + arg, argv[0]);
95 setError(
"-p port is required", argv[0]);
99 result = ParseResult::Success;
102void Args::setError(
const std::string& message,
const std::string& progName)
104 std::cerr <<
"Error: " << message <<
"\n";
105 printUsage(progName);
106 result = ParseResult::Error;
109void Args::printUsage(
const std::string& progName)
112 <<
"Usage: " << progName
113 <<
" -p port [-h machine] [--headless] [--dev true|false] [--language english|french]\n";
114 std::cerr <<
" -p port Port number to connect to (required)\n";
115 std::cerr <<
" -h machine Machine name or IP address (default: localhost)\n";
116 std::cerr <<
" --headless Run without graphics (text output only)\n";
117 std::cerr <<
" --dev true|false Show dev HUD (FPS, time unit, connection info)\n";
118 std::cerr <<
" --language english|french UI language (default: english)\n";
119 std::cerr <<
" --help Show this help message\n";
static constexpr int SUCCESS
Args(int argc, char **argv)
ServerConfig getConfig() const
static constexpr int ERROR
bool isHelpRequested() const
Represents the configuration for the application, including the port, machine, and headless mode.