Boost logo

Boost Users :

From: Steven Mackenzie (boost_at_[hidden])
Date: 2007-08-24 09:22:56


This thread discusses the issue:
http://archives.free.net.ph/message/20070718.222859.2c087966.en.html
(follow that post up and down the thread a couple of posts as necessary).

Basically, that kind of syntax not directly supported by program_options, but
can be coded up by writing some helper classes.

Not worth the effort, much nicer to your users to write an application that
takes more sensible arguments (-d 1 or -d 2 or -d 3).

Note that getting -d or -d=2 or -d=3 to work requires a patch to program_options
itself, described in another interesting thread:
http://archives.free.net.ph/message/20070723.222625.66f39345.en.html

Hope that helps,
Steven

F David Sacerdoti wrote:
> 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