-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
74 lines (60 loc) · 2.27 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
#include <iostream>
#include <FlowUtils/FlowArgParser.h>
#include "Version.h"
#include <FlowUtils/FlowLog.h>
#include <thread>
#include "FlowRa.h"
#include <chrono>
int main(int argc, char *argv[]) {
std::chrono::time_point<std::chrono::system_clock> start, end;
start = std::chrono::system_clock::now();
LOG_INFO << "Working dir: " << FlowFile::getCurrentDirectory();
FlowArgParser fap;
fap.addFlagOption("version", "v", "Print version");
fap.addFlagOption("debug", "d", "Set logging to Debug");
fap.addFlagOption("trace", "T", "Set logging to trace");
fap.addParameterOption("threads", "t", "Number of Threads");
fap.addParameterOption("log", "l", "Logfile");
fap.addIndexOption("file", "Working file", true);
fap.addIndexList("plugins", "Plugins to load");
fap.markList("plugins");
fap.parse(argc, argv);
if (fap.hasFlag("version")) {
LOG_INFO << "FlowRa Version " << VERSION_MAJOR << "." << VERSION_MINOR;
return 0;
}
if (!fap.hasRequiredOptions()) {
LOG_FATAL << "Wrong amount of arguments";
return EXIT_FAILURE;
}
if (fap.hasFlag("trace")) {
LOG_INFO << "Log Level: Trace";
setLogLevel(logging::TRACE);
} else if (fap.hasFlag("debug")) {
LOG_INFO << "Log Level: Debug";
setLogLevel(logging::DEBUG);
}
auto logFile = fap.getString("log");
if (!logFile.empty()) {
LOG_INFO << "Log to file: " << logFile;
logging::setLogFile("log.txt");
}
auto threads = fap.getString("threads");
size_t threadCount = threads.empty() ? std::thread::hardware_concurrency() : std::stoul(threads, nullptr, 10);
LOG_INFO << "Threads used: " << threadCount;
try {
FlowRa flowRa(fap.getString("file"), threadCount, fap.getList("plugins"));
flowRa.run();
LOG_TRACE << "End Run";
} catch (const std::system_error &e) {
LOG_FATAL << "Code " << e.code()
<< " meaning " << e.what() << '\n';
return e.code().value();
}
LOG_INFO << "Done";
end = std::chrono::system_clock::now();
const auto elapsed_seconds = std::chrono::duration_cast<std::chrono::seconds>
(end - start).count();
std::cout << "elapsed time: " << elapsed_seconds << "s\n";
return 0;
}