Boost logo

Boost Users :

From: Steven Mackenzie (boost_at_[hidden])
Date: 2007-07-24 04:02:02


Very useful to me, thanks!

I'm guessing that the implicit_value is distinct from the default_value, so that
the default can be set seperately if the option is completely absent from the
command line?

My worry would be explaining the different command line syntax for applications
with this type of option to my users, but I understand why it is necessary.

Vladimir, will you be merging this? Does it need to be posted to the developers
list instead?

Steven

Bryan Green wrote:
> Attached is a patch to program_options that implements optional argument
> support, in the style of GNU getopt_long. It adds one new method to
> 'value_type': 'implicit_value()'.
> The idea is that, if the option is given without an argument, it is assigned
> an "implicit" value. Otherwise, if the long-option is given an explicit
> argument via the equals sign (--arg=value), or the short-option is given an
> adjacent argument (-avalue), the explicit value will override the implicit one.
>
> For example:
> desc.add_options()
> ("proxy,p", value<int>(&proxy_port)->implicit_value(DefaultProxyPort), "run
> proxy service")
> ;
> ...
> if (vm.count("proxy"))
> enable_the_proxy(proxy_port);
>
> ./prog --proxy --opt2 --opt3
> -> enables proxy on default port.
> ./prog --proxy=9000 --opt2 --opt3
> -> enables proxy on port 9000.
> ./prog --opt2 --opt3
> -> does not enable the proxy.
>
> -Bryan
>
>
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users


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