-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathargumentParser.cpp
More file actions
51 lines (47 loc) · 1.56 KB
/
argumentParser.cpp
File metadata and controls
51 lines (47 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include "argumentParser.hpp"
/**
* Procceses arguments and sets flags and variables
*/
void proccessArguments(int argc,char *argv[], bool* vFlag,string *botToken) {
int c;
bool tokenFlag = false;
while ((c = getopt (argc, argv, "hvt:")) != -1)
switch (c)
{
case 'h':
printf("Hey I am isabot discord echo bot\n");
printf("I accept these parameters : \n");
printf("-h -> print help and exit\n");
printf("-t <bot_token> -> mandatory parameter -t with valid discord bot_token, the bot token must be activated via websocket\n");
printf("-v -> optional parameter, I will print messages I reacted to terminal\n");
printf("I will connect to the server via the bot_token and will be listening on the #isa-bot channel\n");
exit(EXIT_SUCCESS);
break;
case 'v':
*vFlag = true;
break;
case 't':
*botToken = optarg;
tokenFlag = true;
break;
case '?':
if (optopt == 't') {
fprintf (stderr, "Option -%c requires bot access token\n", optopt);
exit(-1);
}
else if (isprint (optopt))
fprintf (stderr, "Unknown option `-%c'.\n", optopt);
else
fprintf (stderr,
"Unknown option character `\\x%x'.\n",
optopt);
break;
default:
abort ();
}
if (!tokenFlag)
{
fprintf(stderr,"The -t parameter is mandatory, please restart the program with -t <bot_token> parameter \n");
exit(EXIT_FAILURE);
}
}