-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathmain_cli.cpp
More file actions
48 lines (36 loc) · 1015 Bytes
/
Copy pathmain_cli.cpp
File metadata and controls
48 lines (36 loc) · 1015 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
43
44
45
46
47
48
#include "cli/p_cli.h"
#include <QCoreApplication>
#include <QFile>
#include <QJsonDocument>
#include <QTextStream>
int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
app.setApplicationName("mjpancake");
QTextStream in(stdin);
QTextStream out(stdout);
if (argc != 2) {
out << "Usage: " << argv[0] << " <libsaki-cli.json>" << endl;
return 1;
}
QJsonObject config;
{
QFile file(argv[1]);
bool ok = file.open(QIODevice::ReadOnly | QIODevice::Text);
if (!ok) {
out << "Failed to poen " << file.fileName() << endl;
return 2;
}
QJsonDocument doc = QJsonDocument::fromJson(file.readAll());
config = doc.object();
}
PCli pCli(config);
auto readLine = [&in, &out]() {
out << "> ";
out.flush();
return in.readLine();
};
for (QString line = readLine(); !line.isNull(); line = readLine())
pCli.command(line);
return 0;
}