Boost logo

Boost :

From: Vladislav Lazarenko (snail_at_[hidden])
Date: 2005-04-20 03:42:14


Good day, guys. I am new to boost and have some qestion concerns
boost::program_options library. I've wrote a simple program (see code below),
and when I trying to pass multiple '--help' option to the program, it throws
exception with reason "multiple_occurrences". This exception reason may confuse
the end-user, I wanna get some more pretty error description.

So, I have only 2 solutions:

1) Prase exception reason and give a user more informative/pretty description.
2) Refactor boost::program_options to enable it to throw exceptions with
informative reason.

I need a hint from professional. BTW, how can I contribute to
boost::program_options? Where can I read some docs?

Thank you very much in advance and sorry for inconvenience.

// Code:

#include <string>
#include <vector>
#include <iostream>
#include <exception>

#include <boost/program_options.hpp>

using namespace std;
namespace po = boost::program_options;

template<class T>
ostream & operator << (ostream & os, const vector<T> & v)
{
     copy(v.begin(), v.end(), ostream_iterator<T>(cout, " "));
     return os;
}

int main(int argc, char *argv[])
{
   try
   {
     po::options_description desc("Options:");

     desc.add_options()
       ("help", "produce help message")
       ("phone", po::value<vector<string> >()->multitoken(), "mobile phone
number to send SMS to")
     ;

     po::variables_map vm;
     po::store(po::parse_command_line(argc, argv, desc), vm);
     po::notify(vm);

     if (vm.count("phone") > 0)
     {
       cout << "Phones: " << vm["phone"].as< vector<string> >() << endl;
     }
   }
   catch(exception & e)
   {
     cerr << "Unable to parse command line: " << e.what() << endl;
     return 1;
   }

   return 0;
}


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk