diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2018-12-07 20:47:51 +0100 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2018-12-07 20:47:51 +0100 |
commit | 53594eabccfb7cd94f4b4d42745af1c0c21fe1ec (patch) | |
tree | 95b8543f3592fd269c3bd923aff85c1071dd3b03 /lib/configuration/commandline.cpp | |
parent | PKGBUILD: add gpg key signing for plugins (diff) | |
download | smolbote-53594eabccfb7cd94f4b4d42745af1c0c21fe1ec.tar.xz |
Configuration: parse command line after parsing config file
- Split CommandLine off Configuration
Diffstat (limited to 'lib/configuration/commandline.cpp')
-rw-r--r-- | lib/configuration/commandline.cpp | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/lib/configuration/commandline.cpp b/lib/configuration/commandline.cpp new file mode 100644 index 0000000..4581c84 --- /dev/null +++ b/lib/configuration/commandline.cpp @@ -0,0 +1,59 @@ +/* + * 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()); + } +} |