Repository navigation
Expand file tree
/
Copy pathmain.cpp
More file actions
59 lines (50 loc) · 1.5 KB
/
Copy pathmain.cpp
File metadata and controls
59 lines (50 loc) · 1.5 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
52
53
54
55
56
57
58
59
#include <iostream>
#include <print>
#include <string>
#include "SearchEngine.h"
enum class Command { UNKNOWN, EXIT, FIND };
Command getCommand(const std::string &input) {
static const std::unordered_map<std::string, Command> commandMap = {
{"find", Command::FIND}, {"exit", Command::EXIT}
};
auto it = commandMap.find(input);
if (it != commandMap.end()) return it->second;
return Command::UNKNOWN;
}
int main(int argc, char *argv[]) {
if (argc < 2) {
std::println("Missing data directory");
}
if (argc == 2) {
SearchEngine search = SearchEngine();
search.addDir(argv[1]);
search.compile();
std::string command = "";
bool shouldExit = false;
while (!shouldExit) {
std::print("> ");
std::cin >> command;
switch (getCommand(command)) {
case Command::FIND: {
std::string searchString = "";
std::getline(std::cin, searchString);
search.find(searchString);
break;
}
case Command::EXIT: {
shouldExit = true;
break;
}
case Command::UNKNOWN: {
std::println("Invalid command");
break;
}
default: {
shouldExit = true;
break;
}
}
}
}
return 0;
}