Use QCommandLineParser instead of by-hand parsing.
This will be more flexible for future CLI options
This commit is contained in:
parent
36470c5061
commit
089acfd84a
2 changed files with 33 additions and 9 deletions
|
@ -24,6 +24,8 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <QMetaType>
|
#include <QMetaType>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
|
#include <QCommandLineParser>
|
||||||
|
|
||||||
#include "passwordhasher.h"
|
#include "passwordhasher.h"
|
||||||
#include "servatrice.h"
|
#include "servatrice.h"
|
||||||
#include "server_logger.h"
|
#include "server_logger.h"
|
||||||
|
@ -34,6 +36,7 @@
|
||||||
#include "version_string.h"
|
#include "version_string.h"
|
||||||
#include <google/protobuf/stubs/common.h>
|
#include <google/protobuf/stubs/common.h>
|
||||||
|
|
||||||
|
|
||||||
RNG_Abstract *rng;
|
RNG_Abstract *rng;
|
||||||
ServerLogger *logger;
|
ServerLogger *logger;
|
||||||
QThread *loggerThread;
|
QThread *loggerThread;
|
||||||
|
@ -111,15 +114,36 @@ int main(int argc, char *argv[])
|
||||||
QCoreApplication app(argc, argv);
|
QCoreApplication app(argc, argv);
|
||||||
app.setOrganizationName("Cockatrice");
|
app.setOrganizationName("Cockatrice");
|
||||||
app.setApplicationName("Servatrice");
|
app.setApplicationName("Servatrice");
|
||||||
|
app.setApplicationVersion(VERSION_STRING);
|
||||||
|
|
||||||
QStringList args = app.arguments();
|
bool testRandom = false;
|
||||||
bool testRandom = args.contains("--test-random");
|
bool testHashFunction = false;
|
||||||
bool testHashFunction = args.contains("--test-hash");
|
bool logToConsole = false;
|
||||||
bool logToConsole = args.contains("--log-to-console");
|
|
||||||
QString configPath;
|
QString configPath;
|
||||||
int hasConfigPath=args.indexOf("--config");
|
|
||||||
if(hasConfigPath > -1 && args.count() > hasConfigPath + 1)
|
QCommandLineParser parser;
|
||||||
configPath = args.at(hasConfigPath + 1);
|
parser.addHelpOption();
|
||||||
|
parser.addVersionOption();
|
||||||
|
|
||||||
|
QCommandLineOption testRandomOpt("test-random", "Test PRNG (chi^2)");
|
||||||
|
parser.addOption(testRandomOpt);
|
||||||
|
|
||||||
|
QCommandLineOption testHashFunctionOpt("test-hash", "Test password hash function");
|
||||||
|
parser.addOption(testHashFunctionOpt);
|
||||||
|
|
||||||
|
QCommandLineOption logToConsoleOpt("log-to-console", "Write server logs to console");
|
||||||
|
parser.addOption(logToConsoleOpt);
|
||||||
|
|
||||||
|
QCommandLineOption configPathOpt("config", "Read server configuration from <file>", "file", "");
|
||||||
|
parser.addOption(configPathOpt);
|
||||||
|
|
||||||
|
parser.process(app);
|
||||||
|
|
||||||
|
testRandom = parser.isSet(testRandomOpt);
|
||||||
|
testHashFunction = parser.isSet(testHashFunctionOpt);
|
||||||
|
logToConsole = parser.isSet(logToConsoleOpt);
|
||||||
|
configPath = parser.value(configPathOpt);
|
||||||
|
|
||||||
|
|
||||||
qRegisterMetaType<QList<int> >("QList<int>");
|
qRegisterMetaType<QList<int> >("QList<int>");
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue