diff --git a/backends/libyahoo2/main.cpp b/backends/libyahoo2/main.cpp index d793742487c9ae034280cc828a6430b23f166919..9c1338399ed839c210d42bb8d8eac1220e61f0ee 100644 --- a/backends/libyahoo2/main.cpp +++ b/backends/libyahoo2/main.cpp @@ -741,60 +741,21 @@ int main (int argc, char* argv[]) { } #endif - std::string configFile; - boost::program_options::variables_map vm; - boost::program_options::options_description desc("Usage: spectrum \nAllowed options"); - desc.add_options() - ("help", "help") - ("host,h", boost::program_options::value(&host)->default_value(""), "Host to connect to") - ("port,p", boost::program_options::value(&port)->default_value(10000), "Port to connect to") - ("config", boost::program_options::value(&configFile)->default_value(""), "Config file") - ; - - try - { - boost::program_options::positional_options_description p; - p.add("config", -1); - boost::program_options::store(boost::program_options::command_line_parser(argc, argv). - options(desc).positional(p).allow_unregistered().run(), vm); - boost::program_options::notify(vm); - - if(vm.count("help")) - { - std::cout << desc << "\n"; - return 1; - } - - if(vm.count("config") == 0) { - std::cout << desc << "\n"; - return 1; - } - } - catch (std::runtime_error& e) - { - std::cout << desc << "\n"; - return 1; - } - catch (...) - { - std::cout << desc << "\n"; - return 1; - } - - Config config(argc, argv); - if (!config.load(configFile)) { - std::cerr << "Can't open " << argv[1] << " configuration file.\n"; + std::string error; + Config *cfg = Config::createFromArgs(argc, argv, error, host, port); + if (cfg == NULL) { + std::cerr << error; return 1; } - Logging::initBackendLogging(&config); + Logging::initBackendLogging(cfg); register_callbacks(); yahoo_set_log_level(YAHOO_LOG_DEBUG); Swift::SimpleEventLoop eventLoop; loop_ = &eventLoop; - np = new YahooPlugin(&config, &eventLoop, host, port); + np = new YahooPlugin(cfg, &eventLoop, host, port); loop_->run(); return 0;