-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
34 lines (27 loc) · 734 Bytes
/
Copy pathmain.cpp
File metadata and controls
34 lines (27 loc) · 734 Bytes
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
#include <iostream>
#include <fstream>
#include <string>
#include "CommandParser.h"
#include "JsonObject.h"
int main(int argc, char **argv) {
if (argc != 3) {
std::cerr << "Usage: " << argv[0] << " [filename] " << '"' << "command" << '"' << "\n";
return -1;
}
std::string command = argv[2];
std::ifstream fin(argv[1]);
if (!fin) {
std::cerr << "Cannot open file.\n";
return -1;
}
std::string json_str;
std::string line;
while (getline(fin, line)) {
json_str += line;
line = "";
}
auto json_object = JsonObject(json_str);
auto parser = CommandParser(command, json_object);
std::cout << parser.execute() << "\n";
return 0;
}