From c72b2de3794c7c5100cc8e007b3c199a2f237fe6 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Tue, 22 Oct 2019 10:35:37 +0300 Subject: Use github.com/Taywee/args to parse command line - This adds 3rd-party/args/args.git subrepository --- lib/configuration/commandline.cpp | 59 ----------------------------- lib/configuration/commandline.h | 79 --------------------------------------- lib/configuration/meson.build | 2 +- 3 files changed, 1 insertion(+), 139 deletions(-) delete mode 100644 lib/configuration/commandline.cpp delete mode 100644 lib/configuration/commandline.h (limited to 'lib') 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 - -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()->default_value(defaultUserConfigLocation()), "Set the configuration file.") - ("no-remote", "Do not accept or send remote commands.") - - ("session,s", po::value(), "Open the selected session.") - ("pick-session", "Show all available sessions and select which one to open.") - - ("args", po::value>(), "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 -#include -#include - -class CommandLine -{ -public: - CommandLine(int argc, char **argv); - - bool exists(const char *path) const - { - return (vm.count(path) > 0); - } - - template - std::optional value(const char *path) const - { - if(vm.count(path) == 0) { - return std::nullopt; - } - - if constexpr(std::is_same_v) { - return std::optional(QString::fromStdString(this->value(path).value())); - //return std::optional(vm[path].as()); - - } else if constexpr(std::is_same_v) { - QStringList r; - for(const std::string &item : this->value>(path).value()) { - r.append(QString::fromStdString(item)); - } - return std::optional(r); - - } else if constexpr(std::is_same_v) { - - if(vm[path].value().type() == typeid(int)) { - return std::optional(std::to_string(vm[path].as())); - } - - if(vm[path].value().type() == typeid(bool)) { - return std::optional(vm[path].as() ? "true" : "false"); - } - - std::string r = vm[path].as(); - - // check if it's a path - if(r.front() == '~') { - r.replace(0, 1, m_homePath); - } - - return std::optional(r); - - } else - return std::optional(vm[path].as()); - } - - 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] ) -- cgit v1.2.1