diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/browser.cpp | 2 | ||||
-rw-r--r-- | src/main.cpp | 53 |
2 files changed, 24 insertions, 31 deletions
diff --git a/src/browser.cpp b/src/browser.cpp index 3a80439..18ccc92 100644 --- a/src/browser.cpp +++ b/src/browser.cpp @@ -64,7 +64,7 @@ void Browser::about() const QStringList Browser::configurationOptions() const { QStringList options; - for(const auto &option : m_config->options()) { + for(const auto &option : m_config->description().options()) { options.append(QString::fromStdString(option->long_name())); } return options; diff --git a/src/main.cpp b/src/main.cpp index e1e7618..2a0d355 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -8,19 +8,18 @@ #include "browser.h" #include "builtins.h" +#include "commandline.h" #include "configuration.h" #include "session/session.h" #include "session/sessiondialog.h" #include "util.h" +#include "version.h" #include <QFile> #include <QLibraryInfo> #include <QPluginLoader> #include <QTranslator> -#include <QVersionNumber> -#include <iostream> #include <memory> #include <plugininterface.h> -#include <version.h> #ifdef _WIN32 #include <cstdio> #include <windows.h> @@ -80,6 +79,17 @@ int main(int argc, char **argv) } #endif + const std::unique_ptr<CommandLine> cmd = std::make_unique<CommandLine>(argc, argv); + // --version + if(cmd->exists("version")) { + return builtins::version(); + } + + // --build + if(cmd->exists("build")) { + return builtins::build(); + } + // Disable Chromium's crash handler so breakpad can capture crashes instead. // This has to be done before QtWebEngine gets initialized. const auto chromiumFlags = qgetenv("QTWEBENGINE_CHROMIUM_FLAGS"); @@ -89,23 +99,11 @@ int main(int argc, char **argv) // create and load configuration std::unique_ptr<Configuration> config = std::make_unique<Configuration>(nullptr); - - if(!config->parse(argc, argv)) { - qWarning("Error parsing command line, check --help for usage."); - return -1; - } - if(!config->parse(config->value<std::string>("config").value())) { + if(!config->parse(cmd->value<std::string>("config").value())) { qWarning("Error parsing config file."); } - - // --version - if(config->exists("version")) { - return builtins::version(); - } - - // --build - if(config->exists("build")) { - return builtins::build(); + if(!config->parse(argc, argv)) { + qWarning("Error parsing command line."); } QVector<QPluginLoader *> plugins; @@ -129,9 +127,8 @@ int main(int argc, char **argv) } } - if(config->exists("help")) { - - return builtins::help(argv[0], config->commandlineOptions(), config->configurationOptions(), pluginCommands); + if(cmd->exists("help")) { + return builtins::help(argv[0], cmd->description(), config->description(), pluginCommands); } // argc, argv, allowSecondary @@ -179,18 +176,14 @@ int main(int argc, char **argv) delete translator; } - // command line arguments - const bool isStandalone = config->exists("no-remote"); - const auto arguments = config->value<std::vector<std::string>>("args"); - const bool pickSession = config->exists("pick-session"); - const auto session = config->value<QString>("session"); + const bool isStandalone = cmd->exists("no-remote"); const auto profile = config->value<QString>("profile.default"); - app.setConfiguration(config); + app.setConfiguration(config); // app takes ownership of config app.setup(plugins); QStringList urls; - if(arguments) { + if(const auto arguments = cmd->value<std::vector<std::string>>("args")) { for(const auto &u : arguments.value()) { if(pluginCommands.contains(QString::fromStdString(u))) { return pluginCommands.value(QString::fromStdString(u))(); @@ -214,13 +207,13 @@ int main(int argc, char **argv) { QJsonObject sessionData; - if(pickSession) { + if(cmd->exists("pick-session")) { auto *dlg = new SessionDialog(); if(const auto pick = dlg->pickSession()) sessionData = pick.value(); else sessionData = Session::fromCommandLine(profile.value(), urls); - } else if(session) { + } else if(const auto session = cmd->value<QString>("session")) { QFile sessionJson(session.value()); if(sessionJson.open(QIODevice::ReadOnly | QIODevice::Text)) { sessionData = QJsonDocument::fromJson(sessionJson.readAll()).object(); |