Skip to content

Commit

Permalink
Command line option for running with some setting set to a given value
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mgrojo committed Nov 8, 2018
1 parent 170fb69 commit 0aa366a
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)))
Expand Down

0 comments on commit 0aa366a

Please sign in to comment.