aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2018-12-05 12:00:13 +0100
committerAqua-sama <aqua@iserlohn-fortress.net>2018-12-05 12:00:13 +0100
commit1eddb7418013e8405f6ff4834eb64396f3a29ff3 (patch)
tree75a72ffb99f84677fa1ffb4c8cc641f1826bdd8b
parentUpdate .desktop and .profile (diff)
downloadsmolbote-1eddb7418013e8405f6ff4834eb64396f3a29ff3.tar.xz
Add builtins::version, ::build and ::help
-rw-r--r--src/builtins.cpp58
-rw-r--r--src/builtins.h25
-rw-r--r--src/main.cpp34
-rw-r--r--src/meson.build2
4 files changed, 88 insertions, 31 deletions
diff --git a/src/builtins.cpp b/src/builtins.cpp
new file mode 100644
index 0000000..242a09f
--- /dev/null
+++ b/src/builtins.cpp
@@ -0,0 +1,58 @@
+/*
+ * This file is part of smolbote. It's copyrighted by the contributors recorded
+ * in the version control history of the file, available from its original
+ * location: https://neueland.iserlohn-fortress.net/gitea/aqua/smolbote
+ *
+ * SPDX-License-Identifier: GPL-3.0
+ */
+
+#include "builtins.h"
+#include <QObject>
+#include <QVersionNumber>
+#include <iostream>
+#include <version.h>
+
+inline std::string tr(const char *text)
+{
+ return QObject::tr(text).toStdString();
+}
+
+int builtins::version()
+{
+ const auto version = QVersionNumber::fromString(QLatin1String(poi_Version)).toString().toStdString();
+ std::cout << tr("smolbote ") << version << std::endl;
+ return 0;
+}
+
+int builtins::build()
+{
+ std::cout << poi_Version << std::endl;
+ return 0;
+}
+
+int builtins::help(const char *cmd,
+ boost::program_options::options_description cmd_opts,
+ boost::program_options::options_description config_opts,
+ CommandHash_t pluginCommands)
+{
+ const auto version = QVersionNumber::fromString(QLatin1String(poi_Version)).toString().toStdString();
+ std::cout << tr("smolbote ") << version << tr(": yet another no-frills browser\n");
+ std::cout << tr("Usage: ") << cmd << tr(" [options] [command/URL(s)]\n\n");
+
+ std::cout << tr("Command-line Options:\n") << cmd_opts << '\n';
+
+ std::cout << tr("Commands: \n");
+ for(auto it = pluginCommands.constBegin(); it != pluginCommands.constEnd(); ++it)
+ std::cout << " " << it.key().toStdString() << '\n';
+ std::cout << '\n';
+
+ std::cout << tr("Configuration Options:\n") << config_opts << '\n';
+
+#ifdef Q_OS_UNIX
+ std::cout << tr("For more information on usage, refer to the manual page smolbote.7\n");
+ std::cout << tr("For more information on configuration, refer to the manual page smolbote.5\n");
+#endif
+
+ std::cout << std::endl;
+ return 0;
+}
diff --git a/src/builtins.h b/src/builtins.h
new file mode 100644
index 0000000..6c7153c
--- /dev/null
+++ b/src/builtins.h
@@ -0,0 +1,25 @@
+/*
+ * This file is part of smolbote. It's copyrighted by the contributors recorded
+ * in the version control history of the file, available from its original
+ * location: https://neueland.iserlohn-fortress.net/gitea/aqua/smolbote
+ *
+ * SPDX-License-Identifier: GPL-3.0
+ */
+
+#ifndef SMOLBOTE_BUILTINS_H
+#define SMOLBOTE_BUILTINS_H
+
+#include <boost/program_options.hpp>
+#include <plugininterface.h>
+
+namespace builtins
+{
+int version();
+int build();
+int help(const char *cmd,
+ boost::program_options::options_description cmd_opts,
+ boost::program_options::options_description config_opts,
+ CommandHash_t pluginCommands);
+}
+
+#endif
diff --git a/src/main.cpp b/src/main.cpp
index bb58782..e1e7618 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -7,6 +7,7 @@
*/
#include "browser.h"
+#include "builtins.h"
#include "configuration.h"
#include "session/session.h"
#include "session/sessiondialog.h"
@@ -88,11 +89,6 @@ int main(int argc, char **argv)
// create and load configuration
std::unique_ptr<Configuration> config = std::make_unique<Configuration>(nullptr);
-#ifdef QT_DEBUG
- QObject::connect(config.get(), &Configuration::settingChanged, [](const std::string &path, const QString &value) {
- qDebug("!!! setting changed %s=[%s]", path.c_str(), qUtf8Printable(value));
- });
-#endif
if(!config->parse(argc, argv)) {
qWarning("Error parsing command line, check --help for usage.");
@@ -104,15 +100,12 @@ int main(int argc, char **argv)
// --version
if(config->exists("version")) {
- auto ver = QVersionNumber::fromString(QLatin1String(poi_Version));
- std::cout << "smolbote " << ver.toString().toStdString() << std::endl;
- return 0;
+ return builtins::version();
}
// --build
if(config->exists("build")) {
- std::cout << poi_Version << std::endl;
- return 0;
+ return builtins::build();
}
QVector<QPluginLoader *> plugins;
@@ -137,27 +130,8 @@ int main(int argc, char **argv)
}
if(config->exists("help")) {
- std::cout << "smolbote " << poi_Version << ": yet another no-frills browser" << std::endl;
- std::cout << "Usage: " << argv[0] << " [options] [command/URL(s)]" << std::endl
- << std::endl;
-
- std::cout << "Command-line Options: " << std::endl
- << config->commandlineOptions() << std::endl;
-
- std::cout << "Commands: " << std::endl;
- for(auto it = pluginCommands.constBegin(); it != pluginCommands.constEnd(); ++it) {
- std::cout << it.key().toStdString() << std::endl;
- }
- std::cout << std::endl;
-
- std::cout << "Configuration Options: " << std::endl
- << config->configurationOptions() << std::endl;
-#ifdef Q_OS_LINUX
- std::cout << std::endl
- << "For more information refer to the manual page smolbote.7" << std::endl;
-#endif
- return 0;
+ return builtins::help(argv[0], config->commandlineOptions(), config->configurationOptions(), pluginCommands);
}
// argc, argv, allowSecondary
diff --git a/src/meson.build b/src/meson.build
index c539fff..ec5f873 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -25,7 +25,7 @@ poi = executable(get_option('poiName'), install: true,
dependencies: [dep_qt5, dep_boost, dep_SingleApplication, dep_genheaders, optdepends,
dep_about, dep_addressbar, dep_bookmarks, dep_configuration, dep_downloads, dep_urlfilter, dep_web],
include_directories: [include],
- sources: ['main.cpp', poi_moc,
+ sources: ['main.cpp', 'builtins.cpp', poi_moc,
'browser.cpp',
'util.cpp', 'util.h',