File tree Expand file tree Collapse file tree 3 files changed +28
-3
lines changed
include/boost/program_options Expand file tree Collapse file tree 3 files changed +28
-3
lines changed Original file line number Diff line number Diff line change @@ -16,16 +16,17 @@ 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_value_name.empty () ? arg : m_value_name);
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
Original file line number Diff line number Diff line change @@ -227,6 +227,13 @@ namespace boost { namespace program_options {
227
227
return this ;
228
228
}
229
229
230
+ /* * Specifies the name used to to the value in help message. */
231
+ typed_value* value_name (const std::string& name)
232
+ {
233
+ m_value_name = name;
234
+ return this ;
235
+ }
236
+
230
237
/* * Specifies an implicit value, which will be used
231
238
if the option is given, but without an adjacent value.
232
239
Using this implies that an explicit value is optional, but if
@@ -354,6 +361,7 @@ namespace boost { namespace program_options {
354
361
355
362
// Default value is stored as boost::any and not
356
363
// as boost::optional to avoid unnecessary instantiations.
364
+ std::string m_value_name;
357
365
boost::any m_default_value;
358
366
std::string m_default_value_as_text;
359
367
boost::any m_implicit_value;
Original file line number Diff line number Diff line change @@ -228,6 +228,21 @@ void test_default_values()
228
228
);
229
229
}
230
230
231
+ void test_value_name ()
232
+ {
233
+ options_description desc (" Supported options" );
234
+ desc.add_options ()
235
+ (" include" , value<string>()->value_name (" directory" ), " Search for headers in 'directory'." )
236
+ ;
237
+
238
+ stringstream ss;
239
+ ss << desc;
240
+ BOOST_CHECK_EQUAL (ss.str (),
241
+ " Supported options:\n "
242
+ " --include directory Search for headers in 'directory'.\n "
243
+ );
244
+ }
245
+
231
246
232
247
int main (int , char * [])
233
248
{
@@ -238,6 +253,7 @@ int main(int, char* [])
238
253
test_long_default_value ();
239
254
test_word_wrapping ();
240
255
test_default_values ();
256
+ test_value_name ();
241
257
return 0 ;
242
258
}
243
259
You can’t perform that action at this time.
0 commit comments