clear error hint went wrongly use command line options

This commit is contained in:
Arthur Schiwon 2015-07-03 16:01:24 +02:00
parent e390c22f96
commit 263fa5882b
2 changed files with 15 additions and 8 deletions

View file

@ -351,19 +351,19 @@ void Application::parseOptions(const QStringList &options)
if (it.hasNext() && !it.peekNext().startsWith(QLatin1String("--"))) {
_logFile = it.next();
} else {
setHelp();
showHint("Log file not specified");
}
} else if (option == QLatin1String("--logdir")) {
if (it.hasNext() && !it.peekNext().startsWith(QLatin1String("--"))) {
_logDir = it.next();
} else {
setHelp();
showHint("Log dir not specified");
}
} else if (option == QLatin1String("--logexpire")) {
if (it.hasNext() && !it.peekNext().startsWith(QLatin1String("--"))) {
_logExpire = it.next().toInt();
} else {
setHelp();
showHint("Log expiration not specified");
}
} else if (option == QLatin1String("--logflush")) {
_logFlush = true;
@ -371,17 +371,15 @@ void Application::parseOptions(const QStringList &options)
if (it.hasNext() && !it.peekNext().startsWith(QLatin1String("--"))) {
QString confDir = it.next();
if (!ConfigFile::setConfDir( confDir )) {
std::cerr << "Invalid path passed to --confdir" << std::endl;
std::exit(1);
showHint("Invalid path passed to --confdir");
}
} else {
showHelp();
showHint("Path for confdir not specified");
}
} else if (option == QLatin1String("--debug")) {
_debugMode = true;
} else {
setHelp();
break;
showHint("Unrecognized option '" + option.toStdString() + "'");
}
}
}
@ -430,6 +428,14 @@ void Application::showHelp()
displayHelpText(helpText);
}
void Application::showHint(std::string errorHint)
{
static QString binName = QFileInfo(QCoreApplication::applicationFilePath()).fileName();
std::cerr << errorHint << std::endl;
std::cerr << "Try '" << binName.toStdString() << " --help' for more information" << std::endl;
std::exit(1);
}
bool Application::debugMode()
{
return _debugMode;

View file

@ -56,6 +56,7 @@ public:
bool giveHelp();
void showHelp();
void showHint(std::string errorHint);
bool debugMode();
void showSettingsDialog();