Ticket #4781: 0001-Add-support-for-a-metavar-in-typed_value.patch

File 0001-Add-support-for-a-metavar-in-typed_value.patch, 2.8 KB (added by mathstuf@…, 11 years ago)

Patch to add metavar method to typed_value

  • boost/program_options/detail/value_semantic.hpp

    From 923b426464653257d5383c8de8ec2cc3b27ba07c Mon Sep 17 00:00:00 2001
    From: Ben Boeckel <MathStuf@gmail.com>
    Date: Fri, 4 Nov 2011 13:13:00 -0400
    Subject: [PATCH 1/2] Add support for a metavar in typed_value
    
    This changes the text for the placeholder argument in the help output.
    It can be used to indicated that a directory path is preferred rather than a
    file path or similar.
    ---
     boost/program_options/detail/value_semantic.hpp |    7 ++++---
     boost/program_options/value_semantic.hpp        |   10 ++++++++++
     2 files changed, 14 insertions(+), 3 deletions(-)
    
    diff --git a/boost/program_options/detail/value_semantic.hpp b/boost/program_options/detail/value_semantic.hpp
    index e4b15d7..ba00924 100644
    a b namespace boost { namespace program_options {  
    1616    std::string
    1717    typed_value<T, charT>::name() const
    1818    {
     19        std::string const& var = (m_metavar.empty() ? arg : m_metavar);
    1920        if (!m_implicit_value.empty() && !m_implicit_value_as_text.empty()) {
    20             std::string msg = "[=arg(=" + m_implicit_value_as_text + ")]";
     21            std::string msg = "[=" + var + "(=" + m_implicit_value_as_text + ")]";
    2122            if (!m_default_value.empty() && !m_default_value_as_text.empty())
    2223                msg += " (=" + m_default_value_as_text + ")";
    2324            return msg;
    2425        }
    2526        else if (!m_default_value.empty() && !m_default_value_as_text.empty()) {
    26             return arg + " (=" + m_default_value_as_text + ")";
     27            return var + " (=" + m_default_value_as_text + ")";
    2728        } else {
    28             return arg;
     29            return var;
    2930        }
    3031    }
    3132
  • boost/program_options/value_semantic.hpp

    diff --git a/boost/program_options/value_semantic.hpp b/boost/program_options/value_semantic.hpp
    index 033009e..0c9da1c 100644
    a b namespace boost { namespace program_options {  
    227227            return this;
    228228        }
    229229
     230        /** Specifies a metavar for the argument. This is the text used for
     231            the argument placeholder in the help output.
     232        */
     233        typed_value* metavar(const std::string& m)
     234        {
     235            m_metavar = m;
     236            return this;
     237        }
     238
    230239        /** Specifies an implicit value, which will be used
    231240            if the option is given, but without an adjacent value.
    232241            Using this implies that an explicit value is optional, but if
    namespace boost { namespace program_options {  
    346355       
    347356        // Default value is stored as boost::any and not
    348357        // as boost::optional to avoid unnecessary instantiations.
     358        std::string m_metavar;
    349359        boost::any m_default_value;
    350360        std::string m_default_value_as_text;
    351361        boost::any m_implicit_value;