29 std::string arg_str(arg);
30 size_t pos = arg_str.find(
'=');
31 std::string flag =
"";
32 std::string value =
"";
33 std::vector<std::string> resp;
35 if (pos != std::string::npos) {
36 flag = arg_str.substr(0, pos);
37 value = arg_str.substr(pos + 1);
43 if (flag.find(
"--") == 0) {
44 flag = flag.substr(2);
45 }
else if (flag.find(
"-") == 0) {
46 flag = flag.substr(1);
47 }
else if (flag.find(
"/") == 0) {
48 flag = flag.substr(1);
52 resp.push_back(value);
75 if (args[0] ==
"help" || args[0] ==
"h" || args[0] ==
"?") {
78 }
else if (args[0] ==
"version" || args[0] ==
"v") {
81 }
else if (args[0] ==
"ip" || args[0] ==
"i") {
82 PRETTY_SUCCESS <<
"Ip is provided: '" << args[1] <<
"'" << std::endl;
83 if (args[1].empty()) {
85 std::cerr <<
"Error: Ip value is required" << std::endl;
89 }
else if (args[0] ==
"port" || args[0] ==
"p") {
90 PRETTY_SUCCESS <<
"Port is provided: '" << args[1] <<
"'" << std::endl;
91 unsigned int port = 0;
92 if (args[1].empty()) {
94 std::cerr <<
"Error: Port number is required" << std::endl;
98 port =
static_cast<unsigned int>(std::stoul(args[1]));
100 catch (
const std::invalid_argument &e) {
101 PRETTY_CRITICAL <<
"Invalid argument: '" << args[1] <<
"' is not a valid number." << std::endl;
102 std::cerr <<
"Invalid argument: '" << args[1] <<
"' is not a valid number." << std::endl;
105 catch (
const std::out_of_range &e) {
106 PRETTY_CRITICAL <<
"Out of range: '" << args[1] <<
"' is too large for an unsigned int." << std::endl;
107 std::cerr <<
"Out of range: '" << args[1] <<
"' is too large for an unsigned int." << std::endl;
111 }
else if (args[0] ==
"debug" || args[0] ==
"d") {
115 }
else if (args[0] ==
"log" || args[0] ==
"l") {
118 }
else if (args[0] ==
"full-screen" || args[0] ==
"fs" || args[0] ==
"fullscreen") {
119 PRETTY_INFO <<
"Full screen is activated" << std::endl;
120 main.setWindowFullscreen(
true);
121 }
else if (args[0] ==
"position-x" || args[0] ==
"px" || args[0] ==
"positionx" || args[0] ==
"posx" || args[0] ==
"pos-x") {
122 unsigned int posx = 0;
123 PRETTY_INFO <<
"Position x is provided: '" << args[1] <<
"'" << std::endl;
124 if (args[1].empty()) {
125 std::cerr <<
"Error: position of x is required." << std::endl;
129 posx =
static_cast<int>(std::stoul(args[1]));
131 catch (
const std::invalid_argument &e) {
132 PRETTY_CRITICAL <<
"Invalid argument: '" << args[1] <<
"' is not a valid number." << std::endl;
133 std::cerr <<
"Invalid argument: '" << args[1] <<
"' is not a valid number." << std::endl;
136 catch (
const std::out_of_range &e) {
137 PRETTY_CRITICAL <<
"Out of range: '" << args[1] <<
"' is too large for an int." << std::endl;
138 std::cerr <<
"Out of range: '" << args[1] <<
"' is too large for an int." << std::endl;
141 main.setWindowPositionX(posx);
142 }
else if (args[0] ==
"position-y" || args[0] ==
"py" || args[0] ==
"positiony" || args[0] ==
"posy" || args[0] ==
"pos-y") {
143 unsigned int posy = 0;
144 PRETTY_INFO <<
"Position y is provided: '" << args[1] <<
"'" << std::endl;
145 if (args[1].empty()) {
146 std::cerr <<
"Error: position of x is required." << std::endl;
150 posy =
static_cast<int>(std::stoul(args[1]));
152 catch (
const std::invalid_argument &e) {
153 PRETTY_CRITICAL <<
"Invalid argument: '" << args[1] <<
"' is not a valid number." << std::endl;
154 std::cerr <<
"Invalid argument: '" << args[1] <<
"' is not a valid number." << std::endl;
157 catch (
const std::out_of_range &e) {
158 PRETTY_CRITICAL <<
"Out of range: '" << args[1] <<
"' is too large for an int." << std::endl;
159 std::cerr <<
"Out of range: '" << args[1] <<
"' is too large for an int." << std::endl;
162 main.setWindowPositionY(posy);
163 }
else if (args[0] ==
"window-width" || args[0] ==
"ww" || args[0] ==
"windowwidth") {
164 unsigned int windowWidth = 0;
165 PRETTY_INFO <<
"Window width is provided: '" << args[1] <<
"'" << std::endl;
166 if (args[1].empty()) {
167 std::cerr <<
"Error: Window width is required." << std::endl;
171 windowWidth =
static_cast<unsigned int>(std::stoul(args[1]));
173 catch (
const std::invalid_argument &e) {
174 PRETTY_CRITICAL <<
"Invalid argument: '" << args[1] <<
"' is not a valid number." << std::endl;
175 std::cerr <<
"Invalid argument: '" << args[1] <<
"' is not a valid number." << std::endl;
178 catch (
const std::out_of_range &e) {
179 PRETTY_CRITICAL <<
"Out of range: '" << args[1] <<
"' is too large for an unsigned int." << std::endl;
180 std::cerr <<
"Out of range: '" << args[1] <<
"' is too large for an unsigned int." << std::endl;
183 main.setWindowWidth(windowWidth);
184 }
else if (args[0] ==
"window-height" || args[0] ==
"wh" || args[0] ==
"windowheight") {
185 unsigned int windowHeight = 0;
186 PRETTY_INFO <<
"Window Height is provided: '" << args[1] <<
"'" << std::endl;
187 if (args[1].empty()) {
188 std::cerr <<
"Error: Window Height is required." << std::endl;
192 windowHeight =
static_cast<unsigned int>(std::stoul(args[1]));
194 catch (
const std::invalid_argument &e) {
195 std::cerr <<
"Invalid argument: '" << args[1] <<
"' is not a valid number." << std::endl;
198 catch (
const std::out_of_range &e) {
199 std::cerr <<
"Out of range: '" << args[1] <<
"' is too large for an unsigned int." << std::endl;
202 main.setWindowHeight(windowHeight);
203 }
else if (args[0] ==
"frame-rate-limit" || args[0] ==
"frl" || args[0] ==
"frameratelimit") {
204 unsigned int frameLimit = 0;
205 PRETTY_INFO <<
"Frame limit is provided: '" << args[1] <<
"'" << std::endl;
206 if (args[1].empty()) {
207 std::cerr <<
"Error: Frame Rate is required." << std::endl;
211 frameLimit =
static_cast<unsigned int>(std::stoul(args[1]));
213 catch (
const std::invalid_argument &e) {
214 std::cerr <<
"Invalid argument: '" << args[1] <<
"' is not a valid number." << std::endl;
217 catch (
const std::out_of_range &e) {
218 std::cerr <<
"Out of range: '" << args[1] <<
"' is too large for an unsigned int." << std::endl;
221 main.setFrameLimit(frameLimit);
222 }
else if (args[0] ==
"window-title" || args[0] ==
"wt" || args[0] ==
"windowtitle") {
223 PRETTY_INFO <<
"Window title is provided: '" << args[1] <<
"'" << std::endl;
224 if (args[1].empty()) {
225 std::cerr <<
"Error: The title for the window is required." << std::endl;
228 main.setWindowTitle(args[1]);
229 }
else if (args[0] ==
"config-file" || args[0] ==
"cf" || args[0] ==
"configfile") {
230 PRETTY_INFO <<
"Config file is provided: '" << args[1] <<
"'" << std::endl;
231 if (args[1].empty()) {
232 std::cerr <<
"Error: TOML config file is required." << std::endl;
235 main.setConfigFile(args[1]);
253 unsigned int index = 1;
255 std::string binName(argv[0]);
256 while (index < argc) {
258 PRETTY_INFO <<
"Flag: '" << arg[0] <<
"', Value: '" << arg[1] <<
"'." << std::endl;
279 int status = MY_SUCCESS;
280 bool help_found =
false;
281 bool version_found =
false;
283 Main MyMain(
"127.0.0.1", 9000, 800, 600,
true,
false,
"R-Type", 0, 0,
"NULL",
false,
false,
false, 20, 20, 60,
"client_config.toml",
false,
false);
296 version_found =
true;
299 catch (
const std::exception &e) {
302 std::cerr <<
"An error occurred: '" << e.
what() <<
"'." << std::endl;
306 if (help_found || version_found || status == MY_ERROR) {
307 PRETTY_INFO <<
"The program exited with status: " << status << std::endl;
315 catch (
const std::exception &e) {
316 std::cerr << e.what() << std::endl;
317 PRETTY_CRITICAL <<
"Failed to load the config file, aborting program." << std::endl;
325 catch (
const std::exception &e) {
326 std::cerr << e.what() << std::endl;
329 PRETTY_INFO <<
"Exit status : '" << status <<
"'." << std::endl;
#define PRETTY_INFO
Info log with details and colour.
#define PRETTY_CRITICAL
Critical log with details and colour.
#define PRETTY_SUCCESS
Success log with details and colour.
void process_given_argument(Main &main, const std::vector< std::string > &args, std::string const &binName)
Process the single argument that is provided.
std::vector< std::string > extract_argument(char *arg)
Extracts the flag and value from a command-line argument.
int RealMain(int argc, char **argv)
The main function for initializing and running the application.
void process_arguments(Main &main, int argc, char **argv)
Processes the command-line arguments and applies them to the main application object.
This is the file in charge of containing the main class and other ressources at the root of the progr...
void DisplayVersion(bool helpMode=false)
Displays version information for the program.
void DisplayHelp(const std::string binName)
The main function of the help display.
This is the class in charge of informing the user that the help flag was found. This is not an error.
const char * what() const noexcept
Retrieves the error message.
This is the class in charge of informing the user that the window frame limit is invalid.
This is the class in charge of informing the user that the port is incorrect.
This is the class in charge of informing the user that the window height is invalid.
This is the class in charge of informing the user that the window width is invalid.
This is the class in charge of informing the user that the window x position is invalid.
This is the class in charge of informing the user that the window Y position is invalid.
This is the class in charge of informing the user was supposed to pass a parameter along with the fla...
This is the class in charge of informing the user that the argument that was provided is not known to...
This is the class in charge of informing the user that the version flag was found....
The Main class is the main class of the program.
void run()
This is the function used to start the program's main section.
std::string getConfigFile() const
Function in charge of returning the path to the config file.
void setConfigFile(const std::string &configFile)
This is the function in charge of seting the config filepath.