Opened 15 years ago

Closed 15 years ago

#1123 closed Bugs (duplicate)

[program_options] patch - optional argument support (gnu getopt_long style)

Reported by: anonymous Owned by: Vladimir Prus
Milestone: To Be Determined Component: program_options
Version: Boost 1.34.1 Severity: Not Applicable
Keywords: Cc:

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.

Change History (2)

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

Refer to ticket 1131 for the patch. I did not realize this ticket was accepted, because I got an error during submission saying it was spam. Perhaps that was just in regards to the attached patch. Anyway, this ticket can be removed in favor of 1131.

comment:2 by Vladimir Prus, 15 years ago

Resolution: duplicate
Status: newclosed

Marking as duplicate of #1131 per comment:1.

Note: See TracTickets for help on using tickets.