Opened 15 years ago

Closed 15 years ago

#1131 closed Patches (fixed)

program_options patch: optional argument support (gnu getopt_long style)

Reported by: Bryan Green <bgreen0@…> 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)

program_options_implicit.patch (4.3 KB ) - added by Bryan Green <bgreen0@…> 15 years ago.
program_options_implicit_2.patch (7.6 KB ) - added by Bryan Green <bgreen0@…> 15 years ago.
updated patch, per mailing list comments

Download all attachments as: .zip

Change History (3)

by Bryan Green <bgreen0@…>, 15 years ago

by Bryan Green <bgreen0@…>, 15 years ago

updated patch, per mailing list comments

comment:1 by Vladimir Prus, 15 years ago

Resolution: fixed
Status: newclosed

(In [38514]) Support for 'implicit' options. Patch from Bryan Green. Fixes #1131.

Note: See TracTickets for help on using tickets.