Boost C++ Libraries: Ticket #1123: [program_options] patch - optional argument support (gnu getopt_long style) https://svn.boost.org/trac10/ticket/1123 <p> 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. </p> <p> For example: desc.add_options() </p> <blockquote> <p> ("proxy,p", value&lt;int&gt;(&amp;proxy_port)-&gt;implicit_value(<a class="missing wiki">DefaultProxyPort</a>), "run </p> </blockquote> <p> proxy service") </p> <blockquote> <p> ; </p> </blockquote> <p> ... if (vm.count("proxy")) </p> <blockquote> <p> enable_the_proxy(proxy_port); </p> </blockquote> <p> ./prog --proxy --opt2 --opt3 </p> <blockquote> <p> -&gt; enables proxy on default port. </p> </blockquote> <p> ./prog --proxy=9000 --opt2 --opt3 </p> <blockquote> <p> -&gt; enables proxy on port 9000. </p> </blockquote> <p> ./prog --opt2 --opt3 </p> <blockquote> <p> -&gt; does not enable the proxy. </p> </blockquote> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/1123 Trac 1.4.3 Bryan Green <bgreen0@…> Mon, 30 Jul 2007 17:50:24 GMT <link>https://svn.boost.org/trac10/ticket/1123#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/1123#comment:1</guid> <description> <p> 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. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Vladimir Prus</dc:creator> <pubDate>Tue, 31 Jul 2007 07:04:30 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/1123#comment:2 https://svn.boost.org/trac10/ticket/1123#comment:2 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">duplicate</span> </li> </ul> <p> Marking as duplicate of <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/1131" title="#1131: Patches: program_options patch: optional argument support (gnu getopt_long style) (closed: fixed)">#1131</a> per <a class="ticket" href="https://svn.boost.org/trac10/ticket/1123#comment:1" title="Comment 1">comment:1</a>. </p> Ticket