Boost logo

Boost Users :

From: Bryan Green (bgreen_at_[hidden])
Date: 2007-07-19 12:13:12


Paul Giaccone writes:
> Bryan Green wrote:
> > Steven Mackenzie writes:
> >
> >> 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, set
> tin
> >> g 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 v
> alu
> >> e
> >> isn't set by the usual ->default method or constructor option, ... Probabl
> y s
> >> ome
> >> some of those could be coded around.
> >>
> >> Personally I think a simple -v 3 is nicer; the -v -v -v style of syntax se
> ems
> >> a
> >> bit verbose to me :-)
> >>
> >
> > Allowing '-v 3' precludes allowing just '-v', which is the common case.
> >
> > As for notifier, does it really work that way? I am interested in a way to
> > track multiple occurrences, but I thought the notifier only got called once
> > at the end.
> >
> > -Bryan
> >
>
> Aren't -vvv and -v -v -v non-standard, and therefore to be deprecated?

I don't know about that, but my goal is to convert from use of GNU longopt
to boost::program_options, without breaking compatibility (for users or
preexisting scripts).

> These smack of smart-arse programming[1] to me. Surely, as has been
> suggested, the standard approach (which is already supported by
> program_options) is to do -v <argument> (or --verbose <argument>). If
> you want to increase the verbosity to 10, just use -v 10, for crying out
> loud, rather than demanding that the hapless user types -v -v -v -v -v
> -v -v -v -v -v or -vvvvvvvvvv and then has to check twice to see whether
> they've put the right number of v's in.

Suggesting -v 10 is quite extreme. I've never known a program to go beyond
three. Typing -vvv seems reasonable to me. As for the "standard approach",
I believe that is to support '-v'. And as I said:

> Allowing '-v 3' precludes allowing just '-v', which is the common case.

Actually, I'm wondering, what constitutes "standard" for option parsing?
On Unix at least, you see many variations. Just consider gcc.

-Bryan


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