/* * 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()); } }