#4543, #4544 Fixed missing command line help text from menu-command and --help option.

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:
Jacob Støren 2019-08-08 10:45:02 +02:00
parent 1caee676bc
commit 81de872c7b
9 changed files with 82 additions and 50 deletions

View File

@ -1127,6 +1127,8 @@ QString RiaApplication::commandLineParameterHelp()
{
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 += m_commandLineHelpText;
return helpText;
}
@ -1297,6 +1299,14 @@ void RiaApplication::setStartDir(const QString& startDir)
m_startupDefaultDirectory = startDir;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaApplication::setCommandLineHelpText(const QString& commandLineHelpText)
{
m_commandLineHelpText = commandLineHelpText;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@ -159,7 +159,8 @@ public:
RiaPreferences* preferences();
void applyPreferences(const RiaPreferences* oldPreferences = nullptr);
static QString commandLineParameterHelp();
QString commandLineParameterHelp();
void setCommandLineHelpText(const QString& commandLineHelpText);
void setCacheDataObject(const QString& key, const QVariant& dataObject);
QVariant cacheDataObject(const QString& key) const;
@ -187,8 +188,7 @@ public:
virtual ApplicationStatus handleArguments(cvf::ProgramOptions* progOpt) = 0;
virtual int launchUnitTestsWithConsole();
virtual void addToRecentFiles(const QString& fileName) {}
virtual void showInformationMessage(const QString& infoText) = 0;
virtual void showErrorMessage(const QString& errMsg) = 0;
virtual void showFormattedTextInMessageBoxOrConsole(const QString& errMsg) = 0;
virtual void launchGrpcServer() = 0;
@ -230,7 +230,7 @@ protected:
std::map<QString, QString> m_fileDialogDefaultDirectories;
QString m_startupDefaultDirectory;
QString m_commandLineHelpText;
QMap<QString, QVariant> m_sessionCache; // Session cache used to store username/passwords per session
std::list<RimCommandObject*> m_commandQueue;

View File

@ -100,6 +100,13 @@ RiaApplication::ApplicationStatus RiaConsoleApplication::handleArguments(cvf::Pr
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
// --------------------------------------------------------
if (cvf::Option o = progOpt->option("unittest"))
@ -324,19 +331,11 @@ RiaApplication::ApplicationStatus RiaConsoleApplication::handleArguments(cvf::Pr
}
//--------------------------------------------------------------------------------------------------
///
///
//--------------------------------------------------------------------------------------------------
void RiaConsoleApplication::showInformationMessage(const QString& text)
void RiaConsoleApplication::showFormattedTextInMessageBoxOrConsole(const QString& errMsg)
{
RiaLogging::info(text);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaConsoleApplication::showErrorMessage(const QString& errMsg)
{
RiaLogging::error(errMsg);
std::cout << errMsg.toStdString();
}
//--------------------------------------------------------------------------------------------------
@ -375,7 +374,7 @@ void RiaConsoleApplication::invokeProcessEvents(QEventLoop::ProcessEventsFlags f
//--------------------------------------------------------------------------------------------------
void RiaConsoleApplication::onProjectOpeningError(const QString& errMsg)
{
showErrorMessage(errMsg);
RiaLogging::error(errMsg);
}
//--------------------------------------------------------------------------------------------------

View File

@ -42,8 +42,7 @@ public:
// Public RiaApplication overrides
void initialize() override;
ApplicationStatus handleArguments(cvf::ProgramOptions* progOpt) override;
void showInformationMessage(const QString& text) override;
void showErrorMessage(const QString& errMsg) override;
void showFormattedTextInMessageBoxOrConsole(const QString& errMsg) override;
void launchGrpcServer() override;
#ifdef ENABLE_GRPC
RiaGrpcServer* grpcServer() const override;

View File

@ -120,6 +120,9 @@
#include <QMessageBox>
#include <QProcessEnvironment>
#include <QTreeView>
#include <QTextEdit>
#include <QGridLayout>
#include <QPushButton>
#include <iostream>
@ -152,6 +155,7 @@ void AppEnum<RiaGuiApplication::RINavigationPolicy>::setUp()
///
//==================================================================================================
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -588,6 +592,13 @@ RiaApplication::ApplicationStatus RiaGuiApplication::handleArguments(cvf::Progra
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
// --------------------------------------------------------
if (cvf::Option o = progOpt->option("unittest"))
@ -1201,33 +1212,43 @@ 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;
msgBox.setIcon(QMessageBox::Information);
msgBox.setWindowTitle("ResInsight");
QGridLayout* layout = new QGridLayout;
dlg.setLayout(layout);
helpText.replace("&", "&amp;");
helpText.replace("<", "&lt;");
helpText.replace(">", "&gt;");
QTextEdit* textEdit = new QTextEdit(&dlg);
layout->addWidget(textEdit, 0, 1, 1, 2);
layout->setColumnStretch(1,3);
helpText = QString("<pre>%1</pre>").arg(helpText);
msgBox.setText(helpText);
QPushButton* okButton = new QPushButton;
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("&", "&amp;");
formattedText.replace("<", "&lt;");
formattedText.replace(">", "&gt;");
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);
}
//--------------------------------------------------------------------------------------------------

View File

@ -130,8 +130,7 @@ public:
ApplicationStatus handleArguments(cvf::ProgramOptions* progOpt) override;
int launchUnitTestsWithConsole() override;
void addToRecentFiles(const QString& fileName) override;
void showInformationMessage(const QString& text) override;
void showErrorMessage(const QString& errMsg) override;
void showFormattedTextInMessageBoxOrConsole(const QString& errMsg) override;
void launchGrpcServer() override;
#ifdef ENABLE_GRPC
RiaGrpcServer* grpcServer() const override;

View File

@ -59,21 +59,25 @@ int main(int argc, char *argv[])
cvf::ProgramOptions progOpt;
bool result = RiaArgumentParser::parseArguments(&progOpt);
const cvf::String usageText = progOpt.usageText(110, 30);
app->initialize();
app->setCommandLineHelpText( cvfqt::Utils::toQString(usageText) );
if (!result)
{
std::vector<cvf::String> unknownOptions = progOpt.unknownOptions();
QStringList unknownOptionsText;
QString unknownOptionsText;
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->showErrorMessage(RiaApplication::commandLineParameterHelp() +
cvfqt::Utils::toQString(usageText) +
unknownOptionsText.join("\n"));
app->showFormattedTextInMessageBoxOrConsole("ERROR: Unknown command line options detected ! \n"
+ unknownOptionsText
+ "\n\n"
+ "The current command line options in ResInsight are:\n"
+ app->commandLineParameterHelp());
if (dynamic_cast<RiaGuiApplication*>(app.get()) == nullptr)
{
return 1;

View File

@ -103,8 +103,8 @@ bool RiaArgumentParser::parseArguments(cvf::ProgramOptions* progOpt)
"[<caseId>] <caseListFile>",
"Supply list of cases to replace in project, performing command file for each case.",
cvf::ProgramOptions::SINGLE_VALUE);
progOpt->registerOption("help", "", "Displays help text.");
progOpt->registerOption("?", "", "Displays help text.");
progOpt->registerOption("help", "", "Displays help text and exits.");
progOpt->registerOption("?", "", "Displays help text and exits.");
progOpt->registerOption("regressiontest", "<folder>", "System command", cvf::ProgramOptions::SINGLE_VALUE);
progOpt->registerOption("updateregressiontestbase", "<folder>", "System command", cvf::ProgramOptions::SINGLE_VALUE);
#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
// 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;
}

View File

@ -192,7 +192,7 @@ void RicHelpCommandLineFeature::onActionTriggered(bool isChecked)
RiaApplication* app = RiaApplication::instance();
QString text = app->commandLineParameterHelp();
app->showInformationMessage(text);
app->showFormattedTextInMessageBoxOrConsole(text);
}
//--------------------------------------------------------------------------------------------------