mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Improved the error text when an unknown option is used. Improved the dialog used to show command line options, and make the text selectable
This commit is contained in:
parent
1caee676bc
commit
81de872c7b
@ -1127,6 +1127,8 @@ QString RiaApplication::commandLineParameterHelp()
|
|||||||
{
|
{
|
||||||
QString helpText = QString("\n%1 v. %2\n").arg(RI_APPLICATION_NAME).arg(RiaApplication::getVersionStringApp(false));
|
QString helpText = QString("\n%1 v. %2\n").arg(RI_APPLICATION_NAME).arg(RiaApplication::getVersionStringApp(false));
|
||||||
helpText += "Copyright Equinor ASA, Ceetron Solution AS, Ceetron AS\n\n";
|
helpText += "Copyright Equinor ASA, Ceetron Solution AS, Ceetron AS\n\n";
|
||||||
|
helpText += m_commandLineHelpText;
|
||||||
|
|
||||||
return helpText;
|
return helpText;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1297,6 +1299,14 @@ void RiaApplication::setStartDir(const QString& startDir)
|
|||||||
m_startupDefaultDirectory = startDir;
|
m_startupDefaultDirectory = startDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void RiaApplication::setCommandLineHelpText(const QString& commandLineHelpText)
|
||||||
|
{
|
||||||
|
m_commandLineHelpText = commandLineHelpText;
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
@ -159,7 +159,8 @@ public:
|
|||||||
RiaPreferences* preferences();
|
RiaPreferences* preferences();
|
||||||
void applyPreferences(const RiaPreferences* oldPreferences = nullptr);
|
void applyPreferences(const RiaPreferences* oldPreferences = nullptr);
|
||||||
|
|
||||||
static QString commandLineParameterHelp();
|
QString commandLineParameterHelp();
|
||||||
|
void setCommandLineHelpText(const QString& commandLineHelpText);
|
||||||
|
|
||||||
void setCacheDataObject(const QString& key, const QVariant& dataObject);
|
void setCacheDataObject(const QString& key, const QVariant& dataObject);
|
||||||
QVariant cacheDataObject(const QString& key) const;
|
QVariant cacheDataObject(const QString& key) const;
|
||||||
@ -187,8 +188,7 @@ public:
|
|||||||
virtual ApplicationStatus handleArguments(cvf::ProgramOptions* progOpt) = 0;
|
virtual ApplicationStatus handleArguments(cvf::ProgramOptions* progOpt) = 0;
|
||||||
virtual int launchUnitTestsWithConsole();
|
virtual int launchUnitTestsWithConsole();
|
||||||
virtual void addToRecentFiles(const QString& fileName) {}
|
virtual void addToRecentFiles(const QString& fileName) {}
|
||||||
virtual void showInformationMessage(const QString& infoText) = 0;
|
virtual void showFormattedTextInMessageBoxOrConsole(const QString& errMsg) = 0;
|
||||||
virtual void showErrorMessage(const QString& errMsg) = 0;
|
|
||||||
|
|
||||||
virtual void launchGrpcServer() = 0;
|
virtual void launchGrpcServer() = 0;
|
||||||
|
|
||||||
@ -230,7 +230,7 @@ protected:
|
|||||||
|
|
||||||
std::map<QString, QString> m_fileDialogDefaultDirectories;
|
std::map<QString, QString> m_fileDialogDefaultDirectories;
|
||||||
QString m_startupDefaultDirectory;
|
QString m_startupDefaultDirectory;
|
||||||
|
QString m_commandLineHelpText;
|
||||||
QMap<QString, QVariant> m_sessionCache; // Session cache used to store username/passwords per session
|
QMap<QString, QVariant> m_sessionCache; // Session cache used to store username/passwords per session
|
||||||
|
|
||||||
std::list<RimCommandObject*> m_commandQueue;
|
std::list<RimCommandObject*> m_commandQueue;
|
||||||
|
@ -100,6 +100,13 @@ RiaApplication::ApplicationStatus RiaConsoleApplication::handleArguments(cvf::Pr
|
|||||||
return KEEP_GOING;
|
return KEEP_GOING;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (progOpt->option("help") || progOpt->option("?"))
|
||||||
|
{
|
||||||
|
this->showFormattedTextInMessageBoxOrConsole("\nThe current command line options in ResInsight are:\n"
|
||||||
|
+ this->commandLineParameterHelp());
|
||||||
|
return RiaApplication::EXIT_COMPLETED;
|
||||||
|
}
|
||||||
|
|
||||||
// Unit testing
|
// Unit testing
|
||||||
// --------------------------------------------------------
|
// --------------------------------------------------------
|
||||||
if (cvf::Option o = progOpt->option("unittest"))
|
if (cvf::Option o = progOpt->option("unittest"))
|
||||||
@ -326,17 +333,9 @@ RiaApplication::ApplicationStatus RiaConsoleApplication::handleArguments(cvf::Pr
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
void RiaConsoleApplication::showInformationMessage(const QString& text)
|
void RiaConsoleApplication::showFormattedTextInMessageBoxOrConsole(const QString& errMsg)
|
||||||
{
|
{
|
||||||
RiaLogging::info(text);
|
std::cout << errMsg.toStdString();
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
///
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
void RiaConsoleApplication::showErrorMessage(const QString& errMsg)
|
|
||||||
{
|
|
||||||
RiaLogging::error(errMsg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@ -375,7 +374,7 @@ void RiaConsoleApplication::invokeProcessEvents(QEventLoop::ProcessEventsFlags f
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
void RiaConsoleApplication::onProjectOpeningError(const QString& errMsg)
|
void RiaConsoleApplication::onProjectOpeningError(const QString& errMsg)
|
||||||
{
|
{
|
||||||
showErrorMessage(errMsg);
|
RiaLogging::error(errMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
@ -42,8 +42,7 @@ public:
|
|||||||
// Public RiaApplication overrides
|
// Public RiaApplication overrides
|
||||||
void initialize() override;
|
void initialize() override;
|
||||||
ApplicationStatus handleArguments(cvf::ProgramOptions* progOpt) override;
|
ApplicationStatus handleArguments(cvf::ProgramOptions* progOpt) override;
|
||||||
void showInformationMessage(const QString& text) override;
|
void showFormattedTextInMessageBoxOrConsole(const QString& errMsg) override;
|
||||||
void showErrorMessage(const QString& errMsg) override;
|
|
||||||
void launchGrpcServer() override;
|
void launchGrpcServer() override;
|
||||||
#ifdef ENABLE_GRPC
|
#ifdef ENABLE_GRPC
|
||||||
RiaGrpcServer* grpcServer() const override;
|
RiaGrpcServer* grpcServer() const override;
|
||||||
|
@ -120,6 +120,9 @@
|
|||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QProcessEnvironment>
|
#include <QProcessEnvironment>
|
||||||
#include <QTreeView>
|
#include <QTreeView>
|
||||||
|
#include <QTextEdit>
|
||||||
|
#include <QGridLayout>
|
||||||
|
#include <QPushButton>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
@ -152,6 +155,7 @@ void AppEnum<RiaGuiApplication::RINavigationPolicy>::setUp()
|
|||||||
///
|
///
|
||||||
//==================================================================================================
|
//==================================================================================================
|
||||||
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@ -588,6 +592,13 @@ RiaApplication::ApplicationStatus RiaGuiApplication::handleArguments(cvf::Progra
|
|||||||
return KEEP_GOING;
|
return KEEP_GOING;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (progOpt->option("help") || progOpt->option("?"))
|
||||||
|
{
|
||||||
|
this->showFormattedTextInMessageBoxOrConsole("The current command line options in ResInsight are:\n"
|
||||||
|
+ this->commandLineParameterHelp());
|
||||||
|
return RiaApplication::EXIT_COMPLETED;
|
||||||
|
}
|
||||||
|
|
||||||
// Unit testing
|
// Unit testing
|
||||||
// --------------------------------------------------------
|
// --------------------------------------------------------
|
||||||
if (cvf::Option o = progOpt->option("unittest"))
|
if (cvf::Option o = progOpt->option("unittest"))
|
||||||
@ -1203,31 +1214,41 @@ void RiaGuiApplication::clearAllSelections()
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
void RiaGuiApplication::showInformationMessage(const QString& text)
|
void RiaGuiApplication::showFormattedTextInMessageBoxOrConsole(const QString& text)
|
||||||
{
|
{
|
||||||
QString helpText = text;
|
// Create a message dialog with cut/paste friendly text
|
||||||
|
QDialog dlg(RiuMainWindow::instance());
|
||||||
|
dlg.setModal(true);
|
||||||
|
|
||||||
QMessageBox msgBox;
|
QGridLayout* layout = new QGridLayout;
|
||||||
msgBox.setIcon(QMessageBox::Information);
|
dlg.setLayout(layout);
|
||||||
msgBox.setWindowTitle("ResInsight");
|
|
||||||
|
|
||||||
helpText.replace("&", "&");
|
QTextEdit* textEdit = new QTextEdit(&dlg);
|
||||||
helpText.replace("<", "<");
|
layout->addWidget(textEdit, 0, 1, 1, 2);
|
||||||
helpText.replace(">", ">");
|
layout->setColumnStretch(1,3);
|
||||||
|
|
||||||
helpText = QString("<pre>%1</pre>").arg(helpText);
|
QPushButton* okButton = new QPushButton;
|
||||||
msgBox.setText(helpText);
|
okButton->setText("Ok");
|
||||||
|
layout->addWidget(okButton,2,2);
|
||||||
|
QObject::connect(okButton, SIGNAL(clicked()), &dlg, SLOT(accept()));
|
||||||
|
|
||||||
msgBox.exec();
|
// Convert text to text edit friendly format
|
||||||
}
|
QString formattedText = text;
|
||||||
|
formattedText.replace("&", "&");
|
||||||
|
formattedText.replace("<", "<");
|
||||||
|
formattedText.replace(">", ">");
|
||||||
|
formattedText = QString("<pre>%1</pre>").arg(formattedText);
|
||||||
|
|
||||||
|
textEdit->setText(formattedText);
|
||||||
|
|
||||||
|
// Resize dialog to fit text etc.
|
||||||
|
textEdit->document()->adjustSize();
|
||||||
|
QSizeF docSize = textEdit->document()->size();
|
||||||
|
dlg.resize( 20 + docSize.width() + 2*layout->margin(),
|
||||||
|
20 + docSize.height() + 2*layout->margin() + layout->spacing() + okButton->sizeHint().height());
|
||||||
|
|
||||||
|
dlg.exec();
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
///
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
void RiaGuiApplication::showErrorMessage(const QString& errMsg)
|
|
||||||
{
|
|
||||||
QErrorMessage errDialog(mainWindow());
|
|
||||||
errDialog.showMessage(errMsg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
@ -130,8 +130,7 @@ public:
|
|||||||
ApplicationStatus handleArguments(cvf::ProgramOptions* progOpt) override;
|
ApplicationStatus handleArguments(cvf::ProgramOptions* progOpt) override;
|
||||||
int launchUnitTestsWithConsole() override;
|
int launchUnitTestsWithConsole() override;
|
||||||
void addToRecentFiles(const QString& fileName) override;
|
void addToRecentFiles(const QString& fileName) override;
|
||||||
void showInformationMessage(const QString& text) override;
|
void showFormattedTextInMessageBoxOrConsole(const QString& errMsg) override;
|
||||||
void showErrorMessage(const QString& errMsg) override;
|
|
||||||
void launchGrpcServer() override;
|
void launchGrpcServer() override;
|
||||||
#ifdef ENABLE_GRPC
|
#ifdef ENABLE_GRPC
|
||||||
RiaGrpcServer* grpcServer() const override;
|
RiaGrpcServer* grpcServer() const override;
|
||||||
|
@ -59,21 +59,25 @@ int main(int argc, char *argv[])
|
|||||||
cvf::ProgramOptions progOpt;
|
cvf::ProgramOptions progOpt;
|
||||||
bool result = RiaArgumentParser::parseArguments(&progOpt);
|
bool result = RiaArgumentParser::parseArguments(&progOpt);
|
||||||
|
|
||||||
|
const cvf::String usageText = progOpt.usageText(110, 30);
|
||||||
app->initialize();
|
app->initialize();
|
||||||
|
app->setCommandLineHelpText( cvfqt::Utils::toQString(usageText) );
|
||||||
|
|
||||||
if (!result)
|
if (!result)
|
||||||
{
|
{
|
||||||
std::vector<cvf::String> unknownOptions = progOpt.unknownOptions();
|
std::vector<cvf::String> unknownOptions = progOpt.unknownOptions();
|
||||||
QStringList unknownOptionsText;
|
QString unknownOptionsText;
|
||||||
for (cvf::String option : unknownOptions)
|
for (cvf::String option : unknownOptions)
|
||||||
{
|
{
|
||||||
unknownOptionsText += QString("Unknown option: %1").arg(cvfqt::Utils::toQString(option));
|
unknownOptionsText += QString("\tUnknown option: %1\n").arg(cvfqt::Utils::toQString(option));
|
||||||
}
|
}
|
||||||
|
|
||||||
const cvf::String usageText = progOpt.usageText(110, 30);
|
app->showFormattedTextInMessageBoxOrConsole("ERROR: Unknown command line options detected ! \n"
|
||||||
app->showErrorMessage(RiaApplication::commandLineParameterHelp() +
|
+ unknownOptionsText
|
||||||
cvfqt::Utils::toQString(usageText) +
|
+ "\n\n"
|
||||||
unknownOptionsText.join("\n"));
|
+ "The current command line options in ResInsight are:\n"
|
||||||
|
+ app->commandLineParameterHelp());
|
||||||
|
|
||||||
if (dynamic_cast<RiaGuiApplication*>(app.get()) == nullptr)
|
if (dynamic_cast<RiaGuiApplication*>(app.get()) == nullptr)
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -103,8 +103,8 @@ bool RiaArgumentParser::parseArguments(cvf::ProgramOptions* progOpt)
|
|||||||
"[<caseId>] <caseListFile>",
|
"[<caseId>] <caseListFile>",
|
||||||
"Supply list of cases to replace in project, performing command file for each case.",
|
"Supply list of cases to replace in project, performing command file for each case.",
|
||||||
cvf::ProgramOptions::SINGLE_VALUE);
|
cvf::ProgramOptions::SINGLE_VALUE);
|
||||||
progOpt->registerOption("help", "", "Displays help text.");
|
progOpt->registerOption("help", "", "Displays help text and exits.");
|
||||||
progOpt->registerOption("?", "", "Displays help text.");
|
progOpt->registerOption("?", "", "Displays help text and exits.");
|
||||||
progOpt->registerOption("regressiontest", "<folder>", "System command", cvf::ProgramOptions::SINGLE_VALUE);
|
progOpt->registerOption("regressiontest", "<folder>", "System command", cvf::ProgramOptions::SINGLE_VALUE);
|
||||||
progOpt->registerOption("updateregressiontestbase", "<folder>", "System command", cvf::ProgramOptions::SINGLE_VALUE);
|
progOpt->registerOption("updateregressiontestbase", "<folder>", "System command", cvf::ProgramOptions::SINGLE_VALUE);
|
||||||
#ifdef USE_UNIT_TESTS
|
#ifdef USE_UNIT_TESTS
|
||||||
@ -120,7 +120,7 @@ bool RiaArgumentParser::parseArguments(cvf::ProgramOptions* progOpt)
|
|||||||
|
|
||||||
// If positional parameter functionality is to be supported, the test for existence of positionalParameters must be removed
|
// If positional parameter functionality is to be supported, the test for existence of positionalParameters must be removed
|
||||||
// This is based on a pull request by @andlaus https://github.com/OPM/ResInsight/pull/162
|
// This is based on a pull request by @andlaus https://github.com/OPM/ResInsight/pull/162
|
||||||
if (!parseOk || progOpt->hasOption("help") || progOpt->hasOption("?") || !progOpt->positionalParameters().empty())
|
if (!parseOk || !progOpt->positionalParameters().empty())
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -192,7 +192,7 @@ void RicHelpCommandLineFeature::onActionTriggered(bool isChecked)
|
|||||||
|
|
||||||
RiaApplication* app = RiaApplication::instance();
|
RiaApplication* app = RiaApplication::instance();
|
||||||
QString text = app->commandLineParameterHelp();
|
QString text = app->commandLineParameterHelp();
|
||||||
app->showInformationMessage(text);
|
app->showFormattedTextInMessageBoxOrConsole(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
Loading…
Reference in New Issue
Block a user