nsnake
Classic snake game for the terminal
Arguments.cpp
1 #include <Config/Arguments.hpp>
2 
3 #include <commander/commander.h> // local files
4 #include <iostream>
5 #include <cstdlib>
6 
7 // Local functions that'll be used as callbacks
8 // for the right switches.
9 
10 void version(command_t* self)
11 {
12  (void)(self);
13 
14  std::cout <<
15  "nsnake v" VERSION " (" DATE ")\n"
16  "\n"
17  " , ,\n"
18  " / \\ This game was made with\n"
19  " ((__-^^-,-^^-__)) and itself is Free Software,\n"
20  " `-_---' `---_-' licensed under the GPLv3\n"
21  " `--|o` 'o|--' <3\n"
22  " \\ ` /\n"
23  " ): :(\n"
24  " :o_o:\n"
25  " -\n"
26  "\n"
27  "Homepage: http://nsnake.alexdantas.net/\n"
28  "Source Code: https://github.com/alexdantas/nsnake/\n"
29  "Contact: Alexandre Dantas <eu@alexdantas.net>\n";
30 
31  command_free(self);
32  exit(EXIT_SUCCESS);
33 }
34 void help(command_t* self)
35 {
36  (void)(self);
37 
38  std::cout <<
39  " _ __ _ __ _ ____ \n"
40  "| |\\ | ( (` | |\\ | / /\\ | |_/ | |_ \n"
41  "|_| \\| _)_) |_| \\| /_/--\\ |_| \\ |_|__ \n"
42  "v" VERSION " (built " DATE ")\n"
43  "\n"
44  "nsnake is the classical snake game on the terminal\n"
45  "\n"
46  "Settings and scores are stored at:\n"
47  " `~/.local/share/nsnake/`\n"
48  "\n"
49  "Usage:\n"
50  " nsnake [options]\n"
51  "\n"
52  " -h, --help Show this message\n"
53  " -v, --version Show game version and contact info\n"
54  "\n"
55  "See also `man nsnake`\n"
56  "Thanks for playing this game :)\n";
57 
58  command_free(self);
59  exit(EXIT_SUCCESS);
60 }
61 
62 void Arguments::parse(int argc, char* argv[])
63 {
64  // commander internal data structure
65  command_t cmd;
66  command_init(&cmd, argv[0], VERSION);
67 
68  command_option(&cmd, "-v", "--version", "Show game version and build date", version);
69  command_option(&cmd, "-h", "--help", "Show instructions", help);
70 
71  command_parse(&cmd, argc, argv);
72  command_free(&cmd);
73 }
74 
void exit()
Warns the user about any errors and warnings found during the program&#39;s execution.
Definition: Globals.cpp:143
char version[3]
Game version (format MMP - Major Minor Patch).
Definition: Globals.cpp:13