diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/configuration/commandline.cpp | 59 | ||||
-rw-r--r-- | lib/configuration/commandline.h | 79 | ||||
-rw-r--r-- | lib/configuration/meson.build | 2 |
3 files changed, 1 insertions, 139 deletions
diff --git a/lib/configuration/commandline.cpp b/lib/configuration/commandline.cpp deleted file mode 100644 index 4581c84..0000000 --- a/lib/configuration/commandline.cpp +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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 "commandline.h" -#include "config.h" -#include <QStandardPaths> - -namespace po = boost::program_options; - -inline std::string defaultUserConfigLocation() -{ -#ifdef CONFIG_PATH_CONFIG - return CONFIG_PATH_CONFIG; -#else - // try to locate an existing config - QString path = QStandardPaths::locate(QStandardPaths::ConfigLocation, "smolbote/smolbote.cfg"); - - // it's possible there is no config, so set the path properly - if(path.isEmpty()) - path = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + "/smolbote/smolbote.cfg"; - - return path.toStdString(); -#endif -} - -CommandLine::CommandLine(int argc, char **argv) - : m_homePath(QStandardPaths::writableLocation(QStandardPaths::HomeLocation).toStdString()) -{ - m_description.add_options() - ("help,h", "Display command-line options list.") - ("version,v", "Display version information.") - ("build", "Display build commit.") - - ("config,c", po::value<std::string>()->default_value(defaultUserConfigLocation()), "Set the configuration file.") - ("no-remote", "Do not accept or send remote commands.") - - ("session,s", po::value<std::string>(), "Open the selected session.") - ("pick-session", "Show all available sessions and select which one to open.") - - ("args", po::value<std::vector<std::string>>(), "Command(s) and/or URL(s).") - ; - - m_arguments.add("args", -1); - - try { - auto cmd = po::command_line_parser(argc, argv); - cmd.allow_unregistered(); - cmd.options(m_description); - cmd.positional(m_arguments); - po::store(cmd.run(), vm); - } catch(const po::error &e) { - qWarning("Error parsing cmd: %s", e.what()); - } -} diff --git a/lib/configuration/commandline.h b/lib/configuration/commandline.h deleted file mode 100644 index 3c4dd81..0000000 --- a/lib/configuration/commandline.h +++ /dev/null @@ -1,79 +0,0 @@ -/* - * 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_COMMANDLINE_H -#define SMOLBOTE_COMMANDLINE_H - -#include <QString> -#include <QStringList> -#include <boost/program_options.hpp> - -class CommandLine -{ -public: - CommandLine(int argc, char **argv); - - bool exists(const char *path) const - { - return (vm.count(path) > 0); - } - - template <typename T> - std::optional<T> value(const char *path) const - { - if(vm.count(path) == 0) { - return std::nullopt; - } - - if constexpr(std::is_same_v<T, QString>) { - return std::optional<QString>(QString::fromStdString(this->value<std::string>(path).value())); - //return std::optional<QString>(vm[path].as<const char*>()); - - } else if constexpr(std::is_same_v<T, QStringList>) { - QStringList r; - for(const std::string &item : this->value<std::vector<std::string>>(path).value()) { - r.append(QString::fromStdString(item)); - } - return std::optional<QStringList>(r); - - } else if constexpr(std::is_same_v<T, std::string>) { - - if(vm[path].value().type() == typeid(int)) { - return std::optional<std::string>(std::to_string(vm[path].as<int>())); - } - - if(vm[path].value().type() == typeid(bool)) { - return std::optional<std::string>(vm[path].as<bool>() ? "true" : "false"); - } - - std::string r = vm[path].as<std::string>(); - - // check if it's a path - if(r.front() == '~') { - r.replace(0, 1, m_homePath); - } - - return std::optional<std::string>(r); - - } else - return std::optional<T>(vm[path].as<T>()); - } - - const boost::program_options::options_description& description() const - { - return m_description; - } - -private: - const std::string m_homePath; - boost::program_options::options_description m_description; - boost::program_options::positional_options_description m_arguments; - boost::program_options::variables_map vm; -}; - -#endif // SMOLBOTE_COMMANDLINE_H diff --git a/lib/configuration/meson.build b/lib/configuration/meson.build index 57bafbc..19f57f4 100644 --- a/lib/configuration/meson.build +++ b/lib/configuration/meson.build @@ -3,7 +3,7 @@ configuration_moc = mod_qt5.preprocess( dependencies: dep_qt5 ) -configuration_lib = static_library('configuration', ['commandline.cpp', 'configuration.cpp', configuration_moc], +configuration_lib = static_library('configuration', ['configuration.cpp', configuration_moc], dependencies: [dep_boost, dep_qt5, autogen_config] ) |