23 #include <boost/program_options/cmdline.hpp>
24 #include <boost/program_options/parsers.hpp>
25 #include <boost/program_options/variables_map.hpp>
27 namespace po = boost::program_options;
42 , show_log_domains(false)
44 , log_precise_timestamps(false)
45 , report_timings(false)
47 , args_(args.begin() + 1, args.end())
50 po::options_description opts_general{
"General options"};
51 opts_general.add_options()
52 (
"help,h",
"prints this message and exits.")
53 (
"version,v",
"displays the server version and exits.")
56 po::options_description opts_server{
"Server configuration"};
57 opts_server.add_options()
58 (
"config,c", po::value<std::string>(),
"specifies the path to the server configuration file. By default this is server.cfg in the server directory.")
59 (
"server-dir,s", po::value<std::string>(),
"specifies the path to the server directory. By default this is the process working directory.")
60 (
"port,p", po::value<unsigned short>(),
"specifies the port number on which the server will listen for client connections.")
63 po::options_description opts_log{
"Logging options"};
64 opts_log.add_options()
65 (
"logdomains",
"lists defined log domains and exits")
66 (
"log-error", po::value<std::string>(),
"sets the severity level of the specified log domain(s) to 'error'. <arg> should be given as a comma-separated list of domains.")
67 (
"log-warning", po::value<std::string>(),
"sets the severity level of the specified log domain(s) to 'warning'. This is the default for all log domains other than 'campaignd' and 'server'.")
68 (
"log-info", po::value<std::string>(),
"sets the severity level of the specified log domain(s) to 'info'. This is the default for the 'campaignd' and 'server' log domains.")
69 (
"log-debug", po::value<std::string>(),
"sets the severity level of the specified log domain(s) to 'debug'.")
70 (
"log-none", po::value<std::string>(),
"disables logging for the specified log domain(s).")
71 (
"log-precise",
"shows the timestamps in log output with more precision.")
72 (
"timings",
"outputs timings for serviced requests to stderr.")
75 po::options_description opts;
76 opts.add(opts_general).add(opts_server).add(opts_log);
78 static const int style = po::command_line_style::default_style ^ po::command_line_style::allow_guessing;
81 po::store(po::command_line_parser(
args_).options(opts).style(style).run(), vm);
83 static const std::map<std::string, lg::severity> log_levels = {
91 if(vm.count(
"help")) {
98 if(vm.count(
"version")) {
102 if(vm.count(
"config")) {
105 if(vm.count(
"server-dir")) {
106 server_dir = vm[
"server-dir"].as<std::string>();
108 if(vm.count(
"port")) {
109 port = vm[
"port"].as<
unsigned short>();
112 if(vm.count(
"logdomains")) {
115 for(
const auto& lvl : log_levels) {
116 const auto& swtch = std::string{
"log-"} + lvl.first;
118 if(vm.count(swtch)) {
125 if(vm.count(
"log-precise")) {
128 if(vm.count(
"timings")) {
bool report_timings
Whether to report timing information for server requests.
utils::optional< std::string > config_file
Path to the add-ons server configuration file.
bool version
True if –version was passed.
utils::optional< unsigned short > port
Port number on which the server will listen for incoming connections.
utils::optional< std::string > server_dir
Path to the add-ons server storage dir.
command_line(int argc, char **argv)
Reads the command line.
std::vector< std::string > args_
bool show_log_domains
True if –logdomains was passed.
std::map< std::string, lg::severity > log_domain_levels
Log domain/severity configuration.
bool log_precise_timestamps
Whether to use higher precision for log timestamps.
severity get_severity() const
std::vector< std::string > read_argv([[maybe_unused]] int argc, [[maybe_unused]] char **argv)
Standard logging facilities (interface).
static domain_map * domains
static std::string at(const std::string &file, int line)
std::vector< std::string > split(const config_attribute_value &val)
campaignd command line options parsing.