[Boost-bugs] [Boost C++ Libraries] #1123: [program_options] patch - optional argument support (gnu getopt_long style)

Subject: [Boost-bugs] [Boost C++ Libraries] #1123: [program_options] patch - optional argument support (gnu getopt_long style)
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2007-07-27 19:13:16


#1123: [program_options] patch - optional argument support (gnu getopt_long style)
------------------------------+---------------------------------------------
 Reporter: anonymous | Owner: vladimir_prus
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: program_options
  Version: Boost 1.34.1 | Severity: Not Applicable
 Keywords: |
------------------------------+---------------------------------------------
 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.

--
Ticket URL: <http://svn.boost.org/trac/boost/ticket/1123>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.


This archive was generated by hypermail 2.1.7 : 2017-02-16 18:49:56 UTC