/*
    Copyright (C) 2012 Bartosz Broda, Jacek Bochenek, Łukasz Biłeńkij, 
    Damian Jaworski, Wojciech Mazur, Dominik Piasecki, Maciej Piasecki, 
    Radosław Ramocki
    
    This program is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your option)
any later version.

    This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. 

    See the LICENSE and COPYING files for more details.
*/

#include "options.h"
#include <iostream>
#include <boost/program_options.hpp>

namespace kbestd
{

	options::options() 
	{
		port_no = 4000;
		print_text = true;
	}

	void parse_options(int ac, char**av, options & opts) 
	{
		namespace po = boost::program_options;
		std::string enc;
		po::options_description basic("Basic options", 100);
		basic.add_options()
			("matrix-dir", po::value<std::string>(& opts.matrix_dir),
				"Path with matrices. Required!")
			("ip", po::value<std::string>(& opts.ip),
				"Ip for kbestd server. Required!")
			("port", po::value<int>(& opts.port_no)->default_value(4000), "Port for takipi server.")
			("mysql-host", po::value<std::string>(& opts.mysql_host)->default_value("localhost"), "Hostname of MySQL database.")
			("mysql-db", po::value<std::string>(& opts.mysql_db)->default_value("clarinws"), "Database name.")
			("mysql-user", po::value<std::string>(& opts.mysql_user)->default_value("clarin"), "Database user name.")
			("mysql-passwd", po::value<std::string>(& opts.mysql_pass)->default_value("clarin"), "Database password.")
			("mysql-port", po::value<int>(& opts.mysql_port)->default_value(3306), "Databse port.")
			("print", po::value<bool>(&opts.print_text)->default_value(true), "If set server will print what is it doing.")
			("help", "Prints this message")
			;

		po::variables_map vm;
		po::store(po::parse_command_line(ac, av, basic), vm);
		po::notify(vm);

		if (vm.count("help")) 
		{
			std::cout << "kbestd by Bartosz Broda, bartosz.broda@pwr.wroc.pl\n" << basic<< std::endl;
			exit(0);
		}
		if (!vm.count("ip")) 
		{
			std::cout << "You need to specify ip of kbest server (this computer)\n" << basic<< std::endl;
			exit(0);
		}

		if (!vm.count("matrix-dir"))
		{
			std::cout << "You need to specify path to matrices!\n"
					  << basic<< std::endl;
			exit(0);
		}
	}

} // namespace takipid

