diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2019-10-22 10:35:37 +0300 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2019-10-22 10:35:37 +0300 |
commit | c72b2de3794c7c5100cc8e007b3c199a2f237fe6 (patch) | |
tree | efa0370529cc128b36c00364d2fc950b1496ec45 /lib/configuration/commandline.h | |
parent | Improve meson.build files (diff) | |
download | smolbote-c72b2de3794c7c5100cc8e007b3c199a2f237fe6.tar.xz |
Use github.com/Taywee/args to parse command line
- This adds 3rd-party/args/args.git subrepository
Diffstat (limited to 'lib/configuration/commandline.h')
-rw-r--r-- | lib/configuration/commandline.h | 79 |
1 files changed, 0 insertions, 79 deletions
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 |