Boost logo

Boost Users :

From: F David Sacerdoti (federicosacerdoti_at_[hidden])
Date: 2007-08-24 00:35:06


As per Volodya's suggestion, posting this question here. He mentioned it
had been discussed, but I was unable to find anything appropriate using
search engines. I apologize in advance if this is a repeat question.

Hi,

I am trying to do a simple thing with your program_options boost
library:

I have a program foo, and I want to invoke it like this:
 foo -d -d -d

I want foo to know "I have counted three -d".

I followed your tutorial and tried this:
                desc.add_options()
                 ("debug,d",po::value< vector<int> >()->default_value(1), "Debug level")
                ;

                po::variables_map vm;
                po::store(po::parse_command_line(argc, argv, desc), vm);
                po::notify(vm);
                
                if (vm.count("debug")) {
                        
                        cout << "Running, debug level: " << vm["debug"].as< vector<int> >().size() << "\n";
              }

But it did not work, always prints "debug level: 0". For background,
this is to make the program compatible with a Python implementation
which uses optparse. I have an extensive testing framework that assumes
this behavior and it would be nice to implement the same with
program_options.

Thanks,
Federico


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net