From 8c5ba61b457c229588cc67a4f1406c868e7a5590 Mon Sep 17 00:00:00 2001 From: mgrojo Date: Mon, 22 Oct 2018 21:23:09 +0200 Subject: [PATCH] Command line option for running with some setting set to a given value There are cases where the default configuration makes impossible to use the application, due to some misbehaviour, like in issue #1560. This new command line option allows users to set any setting to any value. The setting is not saved unless user enters Preferences and saves the current values. This allows overriding the preferences for the session duration from the command line and also overriding the defaults for the first session to work around problems with those defaults. See issue #1588 --- src/Application.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/Application.cpp b/src/Application.cpp index 1c590063..dc37e1fe 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -90,6 +90,7 @@ Application::Application(int& argc, char** argv) : qWarning() << qPrintable(tr(" -s, --sql [file]\tExecute this SQL file after opening the DB")); qWarning() << qPrintable(tr(" -t, --table [table]\tBrowse this table after opening the DB")); qWarning() << qPrintable(tr(" -R, --read-only\tOpen database in read-only mode")); + qWarning() << qPrintable(tr(" -o, --option [group/setting=value]\tRun application with this setting temporarily set to value")); qWarning() << qPrintable(tr(" -v, --version\t\tDisplay the current version")); qWarning() << qPrintable(tr(" [file]\t\tOpen this SQLite database")); m_dontShowMainWindow = true; @@ -113,6 +114,22 @@ Application::Application(int& argc, char** argv) : m_dontShowMainWindow = true; } else if(arguments().at(i) == "-R" || arguments().at(i) == "--read-only") { readOnly = true; + } else if(arguments().at(i) == "-o" || arguments().at(i) == "--option") { + const QString optionWarning = tr("The -o/--option option requires an argument in the form group/setting=value") + if(++i >= arguments().size()) + qWarning() << qPrintable(optionWarning); + else { + QStringList option = arguments().at(i).split("="); + if (option.size() != 2) + qWarning() << qPrintable(optionWarning); + else { + QStringList setting = option.at(0).split("/"); + if (setting.size() != 2) + qWarning() << qPrintable(optionWarning); + else + Settings::setValue(setting.at(0), setting.at(1), option.at(1), /* dont_save_to_disk */ true); + } + } } else { // Other: Check if it's a valid file name if(QFile::exists(arguments().at(i)))