/* * Copyright (c) 2020, Irish Centre for High End Computing (ICHEC), NUI Galway * Authors: * CiarĂ¡n O'Rourke , * Sophie Wenzel-Teuber * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ #include "config.h" #include "../deimos_exception.h" #include #include namespace deimos { namespace util { cli_options Config::parse(int argc, char* argv[]) { define_options(); try { m_parser.parse(argc, argv); } catch (const CLI::ParseError& e) { m_parser.exit(e); throw DeimosException( "Returning after command line parsing. --help or invalid argument(s)"); } return handle_arguments(); } void Config::define_options() { m_parser.require_subcommand(1, 1); m_start = m_parser.add_subcommand("start", "start the server daemon"); m_stop = m_parser.add_subcommand("stop", "stop the server daemon"); m_start ->add_option( "hostname,--hostname", m_hostname, "IP/Hostname to bind to") ->required(); m_start->add_option( "--http", m_http_port, "port to listen on with HTTP protocol"); m_start->add_option( "--http2", m_http2_port, "port to listen on with HTTP2 protocol"); m_start->add_option( "-t,--threads", m_thread_count, "number of threads to listen on"); m_start->add_option( "-l,--logfile", m_log_filename, "name of file to write logs to"); m_parser.set_config("--config"); m_start->add_option( "-w,--write-config", m_config_filename, "write configuration options to file"); } cli_options Config::handle_arguments() { if (m_thread_count <= 0) { m_thread_count = sysconf(_SC_NPROCESSORS_ONLN); } if (!m_config_filename.empty()) { std::ofstream file(m_config_filename); file << m_parser.config_to_str(); file.close(); } return { m_http_port, m_http2_port, m_hostname, m_thread_count, m_log_filename}; } } // namespace util } // namespace deimos