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 {
|
| 16 | 16 | std::string |
| 17 | 17 | typed_value<T, charT>::name() const |
| 18 | 18 | { |
| | 19 | std::string const& var = (m_metavar.empty() ? arg : m_metavar); |
| 19 | 20 | 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 + ")]"; |
| 21 | 22 | if (!m_default_value.empty() && !m_default_value_as_text.empty()) |
| 22 | 23 | msg += " (=" + m_default_value_as_text + ")"; |
| 23 | 24 | return msg; |
| 24 | 25 | } |
| 25 | 26 | 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 + ")"; |
| 27 | 28 | } else { |
| 28 | | return arg; |
| | 29 | return var; |
| 29 | 30 | } |
| 30 | 31 | } |
| 31 | 32 | |
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 {
|
| 227 | 227 | return this; |
| 228 | 228 | } |
| 229 | 229 | |
| | 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 | |
| 230 | 239 | /** Specifies an implicit value, which will be used |
| 231 | 240 | if the option is given, but without an adjacent value. |
| 232 | 241 | Using this implies that an explicit value is optional, but if |
| … |
… |
namespace boost { namespace program_options {
|
| 346 | 355 | |
| 347 | 356 | // Default value is stored as boost::any and not |
| 348 | 357 | // as boost::optional to avoid unnecessary instantiations. |
| | 358 | std::string m_metavar; |
| 349 | 359 | boost::any m_default_value; |
| 350 | 360 | std::string m_default_value_as_text; |
| 351 | 361 | boost::any m_implicit_value; |