Merge pull request #1985 from ctrlaltca/p_1405
Use QCommandLineParser instead of by-hand parsing.
This commit is contained in:
commit
575376403f
2 changed files with 33 additions and 9 deletions
|
@ -24,6 +24,8 @@
|
|||
#include <iostream>
|
||||
#include <QMetaType>
|
||||
#include <QDateTime>
|
||||
#include <QCommandLineParser>
|
||||
|
||||
#include "passwordhasher.h"
|
||||
#include "servatrice.h"
|
||||
#include "server_logger.h"
|
||||
|
@ -34,6 +36,7 @@
|
|||
#include "version_string.h"
|
||||
#include <google/protobuf/stubs/common.h>
|
||||
|
||||
|
||||
RNG_Abstract *rng;
|
||||
ServerLogger *logger;
|
||||
QThread *loggerThread;
|
||||
|
@ -111,15 +114,36 @@ int main(int argc, char *argv[])
|
|||
QCoreApplication app(argc, argv);
|
||||
app.setOrganizationName("Cockatrice");
|
||||
app.setApplicationName("Servatrice");
|
||||
|
||||
QStringList args = app.arguments();
|
||||
bool testRandom = args.contains("--test-random");
|
||||
bool testHashFunction = args.contains("--test-hash");
|
||||
bool logToConsole = args.contains("--log-to-console");
|
||||
app.setApplicationVersion(VERSION_STRING);
|
||||
|
||||
bool testRandom = false;
|
||||
bool testHashFunction = false;
|
||||
bool logToConsole = false;
|
||||
QString configPath;
|
||||
int hasConfigPath=args.indexOf("--config");
|
||||
if(hasConfigPath > -1 && args.count() > hasConfigPath + 1)
|
||||
configPath = args.at(hasConfigPath + 1);
|
||||
|
||||
QCommandLineParser parser;
|
||||
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>");
|
||||
|
||||
|
|
|
@ -32,6 +32,6 @@ QString SettingsCache::guessConfigurationPath(QString & specificPath)
|
|||
return guessFileName;
|
||||
#endif
|
||||
|
||||
guessFileName = QStandardPaths::writableLocation(QStandardPaths::DataLocation) + "/" + fileName;
|
||||
guessFileName = QStandardPaths::writableLocation(QStandardPaths::DataLocation) + "/" + fileName;
|
||||
return guessFileName;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue