22 #include <boost/program_options/cmdline.hpp> 23 #include <boost/program_options/parsers.hpp> 24 #include <boost/program_options/variables_map.hpp> 26 namespace po = boost::program_options;
46 ,
args_(args.begin() + 1, args.end())
49 po::options_description opts_general{
"General options"};
50 opts_general.add_options()
51 (
"help,h",
"prints this message and exits.")
52 (
"version,v",
"displays the server version and exits.")
55 po::options_description opts_server{
"Server configuration"};
56 opts_server.add_options()
57 (
"config,c", po::value<std::string>(),
"specifies the path to the server configuration file. By default this is server.cfg in the server directory.")
58 (
"server-dir,s", po::value<std::string>(),
"specifies the path to the server directory. By default this is the process working directory.")
59 (
"port,p", po::value<unsigned short>(),
"specifies the port number on which the server will listen for client connections.")
62 po::options_description opts_log{
"Logging options"};
63 opts_log.add_options()
64 (
"logdomains",
"lists defined log domains and exits")
65 (
"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.")
66 (
"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'.")
67 (
"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.")
68 (
"log-debug", po::value<std::string>(),
"sets the severity level of the specified log domain(s) to 'debug'.")
69 (
"log-none", po::value<std::string>(),
"disables logging for the specified log domain(s).")
70 (
"log-precise",
"shows the timestamps in log output with more precision.")
71 (
"timings",
"outputs timings for serviced requests to stderr.")
74 po::options_description opts;
75 opts.add(opts_general).add(opts_server).add(opts_log);
77 static const int style = po::command_line_style::default_style ^ po::command_line_style::allow_guessing;
82 static const std::map<std::string, int> log_levels = {
90 if(vm.count(
"help")) {
97 if(vm.count(
"version")) {
101 if(vm.count(
"config")) {
104 if(vm.count(
"server-dir")) {
105 server_dir = vm[
"server-dir"].as<std::string>();
107 if(vm.count(
"port")) {
108 port = vm[
"port"].as<
unsigned short>();
111 if(vm.count(
"logdomains")) {
114 for(
const auto& lvl : log_levels) {
115 const auto& swtch = std::string{
"log-"} + lvl.first;
116 const auto severity = lvl.second;
117 if(vm.count(swtch)) {
124 if(vm.count(
"log-precise")) {
127 if(vm.count(
"timings")) {
static domain_map * domains
bool report_timings
Whether to report timing information for server requests.
std::optional< std::string > server_dir
Path to the add-ons server storage dir.
std::vector< std::string > args_
std::vector< std::string > read_argv(int argc, char **argv)
Reads argv into a vector of STL strings.
static std::string at(const std::string &file, int line)
std::optional< std::string > config_file
Path to the add-ons server configuration file.
std::optional< unsigned short > port
Port number on which the server will listen for incoming connections.
bool version
True if –version was passed.
bool log_precise_timestamps
Whether to use higher precision for log timestamps.
command_line(int argc, char **argv)
Reads the command line.
std::vector< std::string > split(const config_attribute_value &val)
campaignd command line options parsing.
Standard logging facilities (interface).
bool show_log_domains
True if –logdomains was passed.
std::map< std::string, int > log_domain_levels
Log domain/severity configuration.