-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
42 lines (36 loc) · 968 Bytes
/
Copy pathmain.cpp
File metadata and controls
42 lines (36 loc) · 968 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
35
36
37
38
39
40
41
42
#include "Main.h"
#include <iostream>
#include <string>
namespace {
void printUsage(const char* program) {
std::cerr << "Usage: " << program << " <json-file-path> [-q <query>]\n";
}
}
int main(int argc, char** argv) {
if (argc < 2) {
printUsage(argv[0]);
return 1;
}
const std::string jsonPath = argv[1];
std::string query;
for (int i = 2; i < argc; ++i) {
const std::string arg = argv[i];
if (arg == "-q") {
if (i + 1 >= argc) {
std::cerr << "Error: -q requires a query argument\n";
printUsage(argv[0]);
return 1;
}
query = argv[++i];
} else {
std::cerr << "Error: unknown argument '" << arg << "'\n";
printUsage(argv[0]);
return 1;
}
}
Main app(jsonPath);
if (!query.empty()) {
return app.runOnce(query);
}
return app.main();
}