Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r59744 - in trunk/libs/program_options: src test
From: ghost_at_[hidden]
Date: 2010-02-18 04:43:08


Author: vladimir_prus
Date: 2010-02-18 04:43:07 EST (Thu, 18 Feb 2010)
New Revision: 59744
URL: http://svn.boost.org/trac/boost/changeset/59744

Log:
Robustify disambiguation of full/approximate matches.

Fixes #3942.

Text files modified:
   trunk/libs/program_options/src/options_description.cpp | 7 +++++--
   trunk/libs/program_options/test/options_description_test.cpp | 11 +++++++++++
   2 files changed, 16 insertions(+), 2 deletions(-)

Modified: trunk/libs/program_options/src/options_description.cpp
==============================================================================
--- trunk/libs/program_options/src/options_description.cpp (original)
+++ trunk/libs/program_options/src/options_description.cpp 2010-02-18 04:43:07 EST (Thu, 18 Feb 2010)
@@ -306,6 +306,7 @@
                                       bool short_ignore_case) const
     {
         shared_ptr<option_description> found;
+ bool had_full_match = false;
         vector<string> approximate_matches;
         vector<string> full_matches;
         
@@ -323,15 +324,17 @@
             if (r == option_description::full_match)
             {
                 full_matches.push_back(m_options[i]->key(name));
+ found = m_options[i];
+ had_full_match = true;
             }
             else
             {
                 // FIXME: the use of 'key' here might not
                 // be the best approach.
                 approximate_matches.push_back(m_options[i]->key(name));
+ if (!had_full_match)
+ found = m_options[i];
             }
-
- found = m_options[i];
         }
         if (full_matches.size() > 1)
             boost::throw_exception(

Modified: trunk/libs/program_options/test/options_description_test.cpp
==============================================================================
--- trunk/libs/program_options/test/options_description_test.cpp (original)
+++ trunk/libs/program_options/test/options_description_test.cpp 2010-02-18 04:43:07 EST (Thu, 18 Feb 2010)
@@ -53,6 +53,17 @@
     BOOST_CHECK_EQUAL(desc.find("all", true).long_name(), "all");
     BOOST_CHECK_EQUAL(desc.find("all-ch", true).long_name(), "all-chroots");
 
+ options_description desc2;
+ desc2.add_options()
+ ("help", "display this message")
+ ("config", value<string>(), "config file name")
+ ("config-value", value<string>(), "single config value")
+ ;
+
+ BOOST_CHECK_EQUAL(desc2.find("config", true).long_name(), "config");
+ BOOST_CHECK_EQUAL(desc2.find("config-value", true).long_name(),
+ "config-value");
+
 
 // BOOST_CHECK(desc.count_approx("foo") == 1);
 // set<string> a = desc.approximations("f");


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk