|
Boost Users : |
From: Bryan Green (bgreen_at_[hidden])
Date: 2007-07-23 18:26:25
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 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