#include <boost/program_options/options_description.hpp>
#include <boost/program_options/parsers.hpp>
#include <boost/program_options/variables_map.hpp>
#include <boost/tokenizer.hpp>
#include <boost/token_functions.hpp>
using namespace boost;
using namespace boost::program_options;

#include <iostream>
#include <exception>
#include <fstream>
using namespace std;

void printInputs(variables_map vm);


int main(int argc, char* argv[])
{
    vector<string> firstCommand, secondCommand ;

    try {
        namespace po = boost::program_options;

        po::options_description commands("Commands");
        commands.add_options()
            ("firstCommand", po::value< vector<string> >(&firstCommand)->multitoken(), "First command ")
            ("secondCommand",po::value< vector<string> >(&secondCommand)->multitoken(), "Second command")
            ;

        variables_map vm;
        store(command_line_parser(argc, argv).options(commands).run(), vm);
        notify(vm);

        ostream_iterator<string> it(cout, ", ");

        printInputs(vm);

        if(vm.count("firstCommand")) {
            cout << "First command detected" << endl;
            cout << "List of parameters passed: ";
            copy(firstCommand.begin(), firstCommand.end(), it);
            cout << endl << endl;
        }
        if(vm.count("secondCommand")) {
            cout << "Second command detected" << endl;
            cout << "List of parameters passed: ";
            copy(secondCommand.begin(), secondCommand.end(), it);
            cout << endl << endl;
        }
    }
    catch (const std::exception& e) {
        cout << e.what() << "\n";
    }
}

void printInputs(variables_map vm)
{
    int i=0;
    variables_map::iterator it=vm.begin();
    cout << "\n***List of commands detected: " << endl;
    for(it;it!=vm.end();++it) {
        cout <<"Command[" << i << "]: " << it->first << endl;
        ++i;
    }
    cout << endl;
}
