-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
47 lines (41 loc) · 1.76 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
#include <iostream>
#include "SearchServer.h"
#include "InvertedIndex.h"
#include "Converter.h"
#include <iostream>
#include "CLI/CLI.hpp"
#include "cmake_var_parsing.h"
int main(int argc, char** argv) {
try {
CLI::App app{"App description"};
std::string config_path = "./config.json";
app.add_option("--config,-c", config_path, "Configuration file path");
std::string request_path = "./requests.json";
app.add_option("--request,-r", request_path, "Path for request file");
std::string output_path = "./answers.json";
app.add_option("--output,-o", output_path, "Output path for query response file");
bool version_flag=false;
app.add_flag("--version,-v", version_flag, "Show a version of the application");
CLI11_PARSE(app, argc, argv);
if (version_flag){
std::cout << "The app version: " << STR(PROJECT_VER) << std::endl;
} else {
ConverterJSON converter(config_path, request_path, output_path);
converter.validate_config_file(STR(PROJECT_VER));
converter.show_config_info();
InvertedIndex index;
index.update_document_base(converter.get_text_documents());
SearchServer server(index);
auto answers = server.search(converter.get_requests(), converter.get_responses_limit());
converter.put_answers(answers);
std::cout << "The answer is recorded to folder: " << output_path << std::endl;
}
std::cout << "The application completed successfully." << std::endl;
return 0;
}
catch (const std::exception& e){
std::cerr << "Error: " << e.what();
std::cout << "The application exited with an error." << std::endl;
return 1;
}
}