$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r77931 - in trunk: boost/program_options boost/program_options/detail libs/program_options/test
From: ghost_at_[hidden]
Date: 2012-04-12 04:37:38
Author: vladimir_prus
Date: 2012-04-12 04:37:34 EDT (Thu, 12 Apr 2012)
New Revision: 77931
URL: http://svn.boost.org/trac/boost/changeset/77931
Log:
Allow to specify how option's value is named in help message.
Fixes #4781.
Text files modified: 
   trunk/boost/program_options/detail/value_semantic.hpp        |     7 ++++---                                 
   trunk/boost/program_options/value_semantic.hpp               |     8 ++++++++                                
   trunk/libs/program_options/test/options_description_test.cpp |    16 ++++++++++++++++                        
   3 files changed, 28 insertions(+), 3 deletions(-)
Modified: trunk/boost/program_options/detail/value_semantic.hpp
==============================================================================
--- trunk/boost/program_options/detail/value_semantic.hpp	(original)
+++ trunk/boost/program_options/detail/value_semantic.hpp	2012-04-12 04:37:34 EDT (Thu, 12 Apr 2012)
@@ -16,16 +16,17 @@
     std::string
     typed_value<T, charT>::name() const
     {
+        std::string const& var = (m_value_name.empty() ? arg : m_value_name);
         if (!m_implicit_value.empty() && !m_implicit_value_as_text.empty()) {
-            std::string msg = "[=arg(=" + m_implicit_value_as_text + ")]";
+            std::string msg = "[=" + var + "(=" + m_implicit_value_as_text + ")]";
             if (!m_default_value.empty() && !m_default_value_as_text.empty())
                 msg += " (=" + m_default_value_as_text + ")";
             return msg;
         }
         else if (!m_default_value.empty() && !m_default_value_as_text.empty()) {
-            return arg + " (=" + m_default_value_as_text + ")";
+            return var + " (=" + m_default_value_as_text + ")";
         } else {
-            return arg;
+            return var;
         }
     }
 
Modified: trunk/boost/program_options/value_semantic.hpp
==============================================================================
--- trunk/boost/program_options/value_semantic.hpp	(original)
+++ trunk/boost/program_options/value_semantic.hpp	2012-04-12 04:37:34 EDT (Thu, 12 Apr 2012)
@@ -227,6 +227,13 @@
             return this;
         }
 
+        /** Specifies the name used to to the value in help message.  */
+        typed_value* value_name(const std::string& name)
+        {
+            m_value_name = name;
+            return this;
+        }
+
         /** Specifies an implicit value, which will be used
             if the option is given, but without an adjacent value.
             Using this implies that an explicit value is optional, but if
@@ -354,6 +361,7 @@
         
         // Default value is stored as boost::any and not
         // as boost::optional to avoid unnecessary instantiations.
+        std::string m_value_name;
         boost::any m_default_value;
         std::string m_default_value_as_text;
         boost::any m_implicit_value;
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	2012-04-12 04:37:34 EDT (Thu, 12 Apr 2012)
@@ -228,6 +228,21 @@
    );   
 }
 
+void test_value_name()
+{
+    options_description desc("Supported options");
+    desc.add_options()
+        ("include", value<string>()->value_name("directory"), "Search for headers in 'directory'.")
+        ;
+
+    stringstream ss;
+    ss << desc;
+   BOOST_CHECK_EQUAL(ss.str(),
+"Supported options:\n"
+"  --include directory   Search for headers in 'directory'.\n"
+   );
+}
+
 
 int main(int, char* [])
 {
@@ -238,6 +253,7 @@
     test_long_default_value();
     test_word_wrapping();
     test_default_values();
+    test_value_name();
     return 0;
 }