Boost logo

Boost Users :

From: Vladimir Prus (ghost_at_[hidden])
Date: 2005-12-20 02:11:26


Marshall Clow wrote:

> I'm trying to use boost::program_options for the first time, and
> there's a couple things that I am tripping over.
>
> The first is the idea of mutually exclusive options. I can't find any
> support for them in the library, and that surprises me - to the point
> of asking for help.
>
> I have two options, only one of which can be specified; say -frtti
> and -fno_rtti (say).

The simplest way for this to work is to define a single bool option "rtti".
Then, use custom parsers to translate "frtti" and "fno_rtti" to "rtti=off"
and "rtti=on" respectively. See
http://boost.org/doc/html/program_options/howto.html#id2715843
which discusses exactly this "no" prefix handling. As a side effect users
will be able to specity "--rtti=on", but maybe that's not a big problem.

> The other one is that program_options, by default, wants to use
> double hyphens to define options:
> "foo --option1 --option2"
>
> I'm a lot more comfortable with single hyphens:
> "foo -option1 -option2"
>
> Am I missing something basic here?

Yes, I think so. The third parameter of 'parse_command_line' is called
style, and possible values are listed at:
    http://boost.org/doc/html/id2358254.html
(not very nicely, but that's Bookbook fault).

Say, passing

    default_style|allow_long_disguise

should make program_option check for long option even if you specify a
single dash.

- Volodya


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