#include #include #include #include #include using namespace boost; using namespace boost::program_options; #include #include #include using namespace std; void printInputs(variables_map vm); int main(int argc, char* argv[]) { vector firstCommand, secondCommand ; try { namespace po = boost::program_options; po::options_description commands("Commands"); commands.add_options() ("firstCommand", po::value< vector >(&firstCommand)->multitoken(), "First command ") ("secondCommand",po::value< vector >(&secondCommand)->multitoken(), "Second command") ; variables_map vm; store(command_line_parser(argc, argv).options(commands).run(), vm); notify(vm); ostream_iterator 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; }