22 #include <boost/program_options.hpp> 23 #include <boost/filesystem.hpp> 46 boost::program_options::options_description& config_desc,
47 boost::program_options::positional_options_description& pos_desc,
48 int argc,
char** argv)
49 : ConfigFileUsed(false)
51 using boost::filesystem::path;
52 using boost::filesystem::is_regular_file;
53 using boost::program_options::store;
54 using boost::program_options::notify;
55 using boost::program_options::command_line_parser;
56 using boost::program_options::parse_config_file;
57 using boost::program_options::positional_options_description;
59 store(command_line_parser(argc, argv).
options(cmd_desc).positional(pos_desc).run(),
options);
61 std::queue<path> directories;
65 directories.push(path(argv[0]).parent_path());
66 directories.push(SYSCONFDIR);
71 while(directories.size())
74 path configPath = directories.front() / configFile;
76 if(is_regular_file(configPath))
79 store(parse_config_file<char>(configPath.string().c_str(), config_desc,
true),
options);
120 boost::any& v = it->second.value();
123 if(v.type() ==
typeid(int))
125 LOG_SEV(app_log, info) << it->first <<
": " << it->second.as<
int>();
133 }
else if (v.type() ==
typeid(std::vector<string>))
135 std::stringstream ss;
136 for(
string name : it->second.as<std::vector<string>>()) {
139 LOG_SEV(app_log, info) << it->first <<
": " << ss.str();
144 LOG_SEV(app_log, info) <<
"Unknown type[" << v.type().name() <<
"]";
153 return options.at(key).value();
void printConfigToLog()
Prints the given configurations to the log.
#define LOG_SEV(log, lvl)
boost::program_options::variables_map options
Internal map holding the options.
const std::vector< string > & getSearchDirectories() const
Returns a queue of strings.
TESTABLE const boost::any & getValueByKey(const string &key) const
bool usedConfigFile() const
Returns true if the configuration was loaded form a file.
bool has(const string &key)
Tests if a key was specified in the command line or in the config file.
static const char * config
Option to get the configuration filename (type: string)
std::vector< string > searchDirectories