Boost logo

Boost Users :

From: Steven Mackenzie (boost_at_[hidden])
Date: 2007-07-19 03:45:09


Ian McCulloch wrote:
> Bryan Green wrote:
> [snip]
>> While I'm on the subject, you sometimes see something like the following:
>>
>> ./prog -vvv
>> or
>> ./prog -v -v -v
>>
>> This would *increment* the verbosity level three times. I can't see how
>> to replicate this in program_options.
>
> This is something I have asked about before on this list, but at the time
> there was no response. I would be very interested in knowing how to do
> this using boost::program_options!

One complete solution has already been posted, but just for diversity, setting a
notifier function on the variable involves less typing. Something like

int verbosityLevel;
...
verbosityLevel = 0;
...
void VerbosityWatcher( bool val )
{
        ++verbosityLevel;
}
...
desc.add_options()
    ("verbose,v",
        po::bool_switch()
                ->notifier( &VerbosityWatcher ),
        "print extra information")
    ;

Disadvantages are that the value isn't available through vm, the default value
isn't set by the usual ->default method or constructor option, ... Probably some
some of those could be coded around.

Personally I think a simple -v 3 is nicer; the -v -v -v style of syntax seems a
bit verbose to me :-)


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