-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
48 lines (37 loc) · 1.42 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
#include <QCoreApplication>
#include <QCommandLineParser>
#include <QCommandLineOption>
#include <trytotriggermosquittoerror.h>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QCoreApplication::setApplicationName("Mosquitto socket error example");
QCommandLineParser parser;
parser.setApplicationDescription(QString("https://github.com/eclipse/mosquitto/issues/383"));
parser.addHelpOption();
QCommandLineOption hostname("hostname", "Mosquitto server hostname", "hostname" );
QCommandLineOption username("username", "Mosquitto username", "username");
QCommandLineOption password("password", "Mosquitto password", "password");
QCommandLineOption port("port", "port", "port", "8883");
parser.addOption(hostname);
parser.addOption(port);
parser.addOption(username);
parser.addOption(password);
parser.process(a);
// No 'required' option on QCommandLineOption?
if (!parser.isSet(hostname) || !parser.isSet(username) || !parser.isSet(password))
{
qCritical() << "Missing options. Do --help.";
return 1;
}
bool parseOK = false;
int port_int = parser.value(port).toInt(&parseOK);
if (!parseOK)
{
qCritical() << "Not a valid port number";
return 2;
}
TryToTriggerMosquittoError foo(parser.value(hostname), port_int, parser.value(username), parser.value(password));
foo.doStuff();
return a.exec();
}