diff --git a/backends/swiften/main.cpp b/backends/swiften/main.cpp index 65b3fe4f03c4556852c209b170bca8c54b33790f..d9199aeb3dbfba5abb8ac1ff3cedc42659c59e1d 100644 --- a/backends/swiften/main.cpp +++ b/backends/swiften/main.cpp @@ -264,57 +264,18 @@ 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); Swift::SimpleEventLoop eventLoop; loop_ = &eventLoop; - np = new SwiftenPlugin(&config, &eventLoop, host, port); + np = new SwiftenPlugin(cfg, &eventLoop, host, port); loop_->run(); return 0;