-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
67 lines (56 loc) · 1.97 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
* SPDX-FileCopyrightText: 2017-2025 CSSlayer <[email protected]>
*
* SPDX-License-Identifier: LGPL-2.1-or-later
*
*/
#include "protocol.h"
#include <QCommandLineOption>
#include <QCommandLineParser>
#include <QCoreApplication>
#include <QLatin1String>
#include <QLoggingCategory>
#include <QtLogging>
#include <cstdlib>
#include <ktexttemplate/metatype.h>
#include <qcontainerfwd.h>
Q_LOGGING_CATEGORY(generator, "generator");
QtMessageHandler defaultHandler = nullptr;
void logHandler(const QtMsgType type, const QMessageLogContext &context,
const QString &msg) {
defaultHandler(type, context, msg);
if (context.category == QLatin1String("generator") &&
type == QtCriticalMsg) {
::exit(1);
}
}
int main(int argc, char *argv[]) {
defaultHandler = qInstallMessageHandler(logHandler);
QCoreApplication app(argc, argv);
QCommandLineParser parser;
parser.addOption(QCommandLineOption(
"includes", "Comma-separated list of extra includes.", "includes"));
parser.addOption(QCommandLineOption(
"namespace", "Namespace for the generated code.", "namespace"));
parser.addOption(
QCommandLineOption("directory", "Output directory.", "directory", "."));
parser.addHelpOption();
parser.addPositionalArgument("files", "Input files.",
"[deps_protocol_file] main_protocol_file");
parser.process(app);
EmitOptions options;
if (parser.isSet("includes")) {
options.extraIncludes_ = parser.values("includes");
}
if (parser.isSet("namespace")) {
options.namespaces_ = parser.value("namespace").split("::");
}
options.directory_ = parser.value("directory");
const auto filenames = parser.positionalArguments();
KTextTemplate::registerMetaType<Message>();
KTextTemplate::registerMetaType<Message *>();
KTextTemplate::registerMetaType<Argument>();
Protocol protocol(filenames);
protocol.generate(options);
return 0;
}