aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2018-12-08 13:34:21 +0100
committerAqua-sama <aqua@iserlohn-fortress.net>2018-12-08 13:34:21 +0100
commit8ec2d92953e3d72664bb9bf545bddaf0c0d851a1 (patch)
treef81ed0e366ca84157d18bbb128fb3a83e0d47b79
parentSplit crash handler code off main (diff)
downloadsmolbote-8ec2d92953e3d72664bb9bf545bddaf0c0d851a1.tar.xz
Fix options not getting overwritten by command line
-rw-r--r--lib/configuration/configuration.cpp29
-rw-r--r--lib/configuration/configuration.h5
-rw-r--r--src/main.cpp8
3 files changed, 12 insertions, 30 deletions
diff --git a/lib/configuration/configuration.cpp b/lib/configuration/configuration.cpp
index 5ddb960..9b84166 100644
--- a/lib/configuration/configuration.cpp
+++ b/lib/configuration/configuration.cpp
@@ -32,7 +32,7 @@ inline std::string defaultUserConfigLocation()
#endif
}
-Configuration::Configuration(QObject *parent)
+Configuration::Configuration(int argc, char **argv, const std::string &path, QObject *parent)
: QObject(parent)
, m_homePath(QStandardPaths::writableLocation(QStandardPaths::HomeLocation).toStdString())
{
@@ -117,30 +117,21 @@ Configuration::Configuration(QObject *parent)
("downloads.path", po::value<std::string>()->default_value(CONFIG_PATH_DOWNLOADS))
("downloads.shortcut", po::value<std::string>()->default_value(CONFIG_SHORTCUT_WINDOW_DOWNLOADS))
;
-}
-
-bool Configuration::parse(const std::string &path)
-{
- std::ifstream f(path, std::ifstream::in);
-
- // parse_config_file(file, options_description, allow_unregistered)
- po::store(po::parse_config_file(f, configuration_desc, true), vm);
- return true;
-}
-bool Configuration::parse(int argc, char **argv)
-{
- try {
+ // po::store will only overwrite values that are default, so:
+ // 1. parse command line
+ {
auto cmd = po::command_line_parser(argc, argv);
cmd.allow_unregistered();
cmd.options(configuration_desc);
po::store(cmd.run(), vm);
- } catch(const po::error &e) {
- qWarning("Error parsing command line: %s", e.what());
- return false;
}
-
- return true;
+ // 2. parse config file
+ {
+ std::ifstream f(path, std::ifstream::in);
+ // parse_config_file(file, options_description, allow_unregistered)
+ po::store(po::parse_config_file(f, configuration_desc, true), vm);
+ }
}
QHash<QString, QString> Configuration::section(const std::string &prefix) const
diff --git a/lib/configuration/configuration.h b/lib/configuration/configuration.h
index fd18fc9..162fbd7 100644
--- a/lib/configuration/configuration.h
+++ b/lib/configuration/configuration.h
@@ -23,12 +23,9 @@ class Configuration : public QObject
Q_OBJECT
public:
- explicit Configuration(QObject *parent = nullptr);
+ explicit Configuration(int argc, char** argv, const std::string &path, QObject *parent = nullptr);
~Configuration() = default;
- bool parse(const std::string &path);
- bool parse(int argc, char **argv);
-
bool exists(const char *path)
{
return vm.count(path) ? true : false;
diff --git a/src/main.cpp b/src/main.cpp
index e718722..d9e1c6a 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -64,13 +64,7 @@ int main(int argc, char **argv)
}
// create and load configuration
- std::unique_ptr<Configuration> config = std::make_unique<Configuration>(nullptr);
- if(!config->parse(cmd->value<std::string>("config").value())) {
- qWarning("Error parsing config file.");
- }
- if(!config->parse(argc, argv)) {
- qWarning("Error parsing command line.");
- }
+ std::unique_ptr<Configuration> config = std::make_unique<Configuration>(argc, argv, cmd->value<std::string>("config").value());
QVector<QPluginLoader *> plugins;
CommandHash_t pluginCommands;