diff --git a/backends/smstools3/main.cpp b/backends/smstools3/main.cpp index 16b172adaa8acca44ff13e4cf97738c0c434070f..31a22b78381250d3cd1d1eb6907cb8249345a726 100644 --- a/backends/smstools3/main.cpp +++ b/backends/smstools3/main.cpp @@ -260,56 +260,16 @@ int main (int argc, char* argv[]) { return -1; } - 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); - std::string error; - StorageBackend *storageBackend = StorageBackend::createBackend(&config, error); + StorageBackend *storageBackend = StorageBackend::createBackend(cfg, error); if (storageBackend == NULL) { if (!error.empty()) { std::cerr << error << "\n"; @@ -323,7 +283,7 @@ int main (int argc, char* argv[]) { Swift::SimpleEventLoop eventLoop; loop_ = &eventLoop; - np = new SMSNetworkPlugin(&config, &eventLoop, host, port); + np = new SMSNetworkPlugin(cfg, &eventLoop, host, port); loop_->run(); return 0;