Opened 15 years ago
Closed 15 years ago
#1131 closed Patches (fixed)
program_options patch: optional argument support (gnu getopt_long style)
Reported by: | Owned by: | Vladimir Prus | |
---|---|---|---|
Milestone: | To Be Determined | Component: | program_options |
Version: | Boost 1.34.1 | Severity: | Problem |
Keywords: | Cc: | bgreen@… |
Description
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.
Attachments (2)
Change History (3)
by , 15 years ago
Attachment: | program_options_implicit.patch added |
---|
by , 15 years ago
Attachment: | program_options_implicit_2.patch added |
---|
comment:1 by , 15 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
updated patch, per mailing list comments