Boost C++ Libraries: Ticket #1131: program_options patch: optional argument support (gnu getopt_long style) https://svn.boost.org/trac10/ticket/1131 <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/1131 Trac 1.4.3 Bryan Green <bgreen0@…> Mon, 30 Jul 2007 17:33:53 GMT attachment set https://svn.boost.org/trac10/ticket/1131 https://svn.boost.org/trac10/ticket/1131 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">program_options_implicit.patch</span> </li> </ul> Ticket Bryan Green <bgreen0@…> Wed, 08 Aug 2007 18:17:24 GMT attachment set https://svn.boost.org/trac10/ticket/1131 https://svn.boost.org/trac10/ticket/1131 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">program_options_implicit_2.patch</span> </li> </ul> <p> updated patch, per mailing list comments </p> Ticket Vladimir Prus Wed, 08 Aug 2007 18:40:50 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/1131#comment:1 https://svn.boost.org/trac10/ticket/1131#comment:1 <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">fixed</span> </li> </ul> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/38514" title="Support for 'implicit' options. Patch from Bryan Green. Fixes #1131. ">[38514]</a>) Support for 'implicit' options. Patch from Bryan Green. Fixes <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>. </p> Ticket