Headless: handle unknown command arguments better

This commit is contained in:
Gaute Lindkvist 2019-05-06 12:46:44 +02:00
parent 911b69b56f
commit 07903a6324
4 changed files with 35 additions and 6 deletions

View File

@ -105,8 +105,15 @@ RiaApplication::ApplicationStatus RiaConsoleApplication::handleArguments(cvf::Pr
if (cvf::Option o = progOpt->option("unittest"))
{
int testReturnValue = launchUnitTestsWithConsole();
return testReturnValue == 0 ? RiaApplication::EXIT_COMPLETED : RiaApplication::EXIT_WITH_ERROR;
if (testReturnValue == 0)
{
return RiaApplication::EXIT_COMPLETED;
}
else
{
RiaLogging::error("Error running unit tests");
return RiaApplication::EXIT_WITH_ERROR;
}
}
if (cvf::Option o = progOpt->option("startdir"))

View File

@ -594,8 +594,15 @@ RiaApplication::ApplicationStatus RiaGuiApplication::handleArguments(cvf::Progra
if (cvf::Option o = progOpt->option("unittest"))
{
int testReturnValue = launchUnitTestsWithConsole();
return testReturnValue == 0 ? RiaApplication::EXIT_COMPLETED : RiaApplication::EXIT_WITH_ERROR;
if (testReturnValue == 0)
{
return RiaApplication::EXIT_COMPLETED;
}
else
{
RiaLogging::error("Error running unit tests");
return RiaApplication::EXIT_WITH_ERROR;
}
}
if (cvf::Option o = progOpt->option("regressiontest"))

View File

@ -49,9 +49,22 @@ int main(int argc, char *argv[])
if (!result)
{
std::vector<cvf::String> unknownOptions = progOpt.unknownOptions();
QStringList unknownOptionsText;
for (cvf::String option : unknownOptions)
{
unknownOptionsText += QString("Unknown option: %1").arg(cvfqt::Utils::toQString(option));
}
const cvf::String usageText = progOpt.usageText(110, 30);
app->showInformationMessage(RiaApplication::commandLineParameterHelp() + cvfqt::Utils::toQString(usageText));
app->showErrorMessage(RiaApplication::commandLineParameterHelp() +
cvfqt::Utils::toQString(usageText) +
unknownOptionsText.join('\n'));
app->cleanupBeforeProgramExit();
if (dynamic_cast<RiaGuiApplication*>(app.get()) == nullptr)
{
return 1;
}
}
QLocale::setDefault(QLocale(QLocale::English, QLocale::UnitedStates));
@ -64,7 +77,7 @@ int main(int argc, char *argv[])
}
else if (status == RiaApplication::EXIT_WITH_ERROR)
{
return 1;
return 2;
}
else if (status == RiaApplication::KEEP_GOING)
{

View File

@ -106,7 +106,9 @@ bool RiaArgumentParser::parseArguments(cvf::ProgramOptions* progOpt)
progOpt->registerOption("?", "", "Displays help text.");
progOpt->registerOption("regressiontest", "<folder>", "System command", cvf::ProgramOptions::SINGLE_VALUE);
progOpt->registerOption("updateregressiontestbase", "<folder>", "System command", cvf::ProgramOptions::SINGLE_VALUE);
#ifdef USE_UNIT_TESTS
progOpt->registerOption("unittest", "", "System command");
#endif
progOpt->registerOption("ignoreArgs", "", "Ignore all arguments. Mostly for testing purposes");
progOpt->setOptionPrefix(cvf::ProgramOptions::DOUBLE_DASH);