-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
91 lines (82 loc) · 2.17 KB
/
main.cpp
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include <iostream>
#include <sstream>
#include <string>
#include "Client.hpp"
#include "FileEncryptor.hpp"
#include "LoggerModule.hpp"
int runClient()
{
try
{
Client client;
client.handleRequest();
}
catch (const std::exception& e)
{
WARN_LOG(
"Unhandled exception reached main: {}\nPlease review logs history. "
"If all requests were successful, please ignore this message.",
e.what());
return EXIT_FAILURE;
}
catch (...)
{
CRITICAL_LOG("An unknown exception reached main.", "");
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
void printHelp()
{
const std::string help =
"Usage: ./client_app [OPTIONS]\n"
"\nOptions:\n"
" -h, --help Show this help message and exit.\n"
" --decrypt Run in decryption mode - currently not supported.\n"
" --log=LEVEL Set the logging level (DEBUG, CRITICAL).\n";
LOG("{}",help);
}
int main(int argc, char const* const* argv)
{
try
{
LoggerModule::init();
}
catch (const std::exception& e)
{
std::cerr << "Failed to initialize logging: " << e.what() << std::endl;
return EXIT_FAILURE;
}
/*bool decryptMode = false;*/
LoggerModule::setLogLevel(spdlog::level::info);
for (int i = 1; i < argc; ++i)
{
std::string arg = argv[i];
if (arg == "--decrypt")
{
LOG("Decryption mode is currently not supported.", "");
}
else if (arg == "--log=DEBUG")
{
LoggerModule::setLogLevel(spdlog::level::debug);
WARN_LOG("Running in debug mode.", "");
}
else if (arg == "--log=CRITICAL")
{
LoggerModule::setLogLevel(spdlog::level::critical);
CRITICAL_LOG("Running in critical mode.", "");
}
else if (arg == "-h" || arg == "--help")
{
printHelp();
return EXIT_SUCCESS;
}
else
{
std::cerr << "Unknown option: " << arg << std::endl;
printHelp();
return EXIT_FAILURE;
}
}
return runClient();
}