From 3720df9cbef999373e1388c7d7e92f396dbabaaf Mon Sep 17 00:00:00 2001 From: Jan Kaluza Date: Mon, 22 Oct 2012 12:26:44 +0200 Subject: [PATCH] Fixed Twitter backend --- backends/twitter/main.cpp | 61 +++++++-------------------------------- 1 file changed, 10 insertions(+), 51 deletions(-) diff --git a/backends/twitter/main.cpp b/backends/twitter/main.cpp index b3404d82..5cbf2def 100644 --- a/backends/twitter/main.cpp +++ b/backends/twitter/main.cpp @@ -27,58 +27,17 @@ 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"; - return 1; - } - - Logging::initBackendLogging(&config); - std::string error; + Config *cfg = Config::createFromArgs(argc, argv, error, host, port); + if (cfg == NULL) { + std::cerr << error; + return 1; + } + + Logging::initBackendLogging(cfg); + StorageBackend *storagebackend; - - storagebackend = StorageBackend::createBackend(&config, error); + storagebackend = StorageBackend::createBackend(cfg, error); if (storagebackend == NULL) { LOG4CXX_ERROR(logger, "Error creating StorageBackend! " << error) return -2; @@ -91,7 +50,7 @@ int main (int argc, char* argv[]) { Swift::SimpleEventLoop eventLoop; loop_ = &eventLoop; - np = new TwitterPlugin(&config, &eventLoop, storagebackend, host, port); + np = new TwitterPlugin(cfg, &eventLoop, storagebackend, host, port); loop_->run(); return 0;