Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r57271 - in trunk/libs/program_options: src test
From: ghost_at_[hidden]
Date: 2009-11-01 05:44:49


Author: vladimir_prus
Date: 2009-11-01 05:44:49 EST (Sun, 01 Nov 2009)
New Revision: 57271
URL: http://svn.boost.org/trac/boost/changeset/57271

Log:
Put description to next line if we'd overflow otherwise.
Fixes #689.

Patch from Sascha Ochsenknecht.

Text files modified:
   trunk/libs/program_options/src/options_description.cpp | 20 ++++++++++++++++----
   trunk/libs/program_options/test/options_description_test.cpp | 18 ++++++++++++++++++
   2 files changed, 34 insertions(+), 4 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 2009-11-01 05:44:49 EST (Sun, 01 Nov 2009)
@@ -504,11 +504,18 @@
 
             if (!opt.description().empty())
             {
- for(unsigned pad = first_column_width - ss.str().size();
- pad > 0;
- --pad)
+ if (ss.str().size() >= first_column_width)
                 {
- os.put(' ');
+ os.put('\n'); // first column is too long, lets put description in new line
+ for (unsigned pad = first_column_width; pad > 0; --pad)
+ {
+ os.put(' ');
+ }
+ } else {
+ for(unsigned pad = first_column_width - ss.str().size(); pad > 0; --pad)
+ {
+ os.put(' ');
+ }
                 }
             
                 format_description(os, opt.description(),
@@ -533,6 +540,11 @@
             ss << " " << opt.format_name() << ' ' << opt.format_parameter();
             width = (max)(width, static_cast<unsigned>(ss.str().size()));
         }
+ /* this is the column were description should start, if first
+ column is longer, we go to a new line */
+ unsigned start_of_description_column = m_line_length / 2;
+
+ width = (min)(width, start_of_description_column-1);
         
         /* add an additional space to improve readability */
         ++width;

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 2009-11-01 05:44:49 EST (Sun, 01 Nov 2009)
@@ -76,10 +76,28 @@
     ss << desc;
 }
 
+void test_long_default_value()
+{
+ options_description desc;
+ desc.add_options()
+ ("cfgfile,c",
+ value<std::string>()->default_value("/usr/local/etc/myprogramXXXXXXXXX/configuration.conf"),
+ "the configfile");
+
+ stringstream ss;
+ ss << desc;
+ BOOST_CHECK_EQUAL(ss.str(),
+" -c [ --cfgfile ] arg (=/usr/local/etc/myprogramXXXXXXXXX/configuration.conf)\n"
+" the configfile\n"
+ );
+
+}
+
 int main(int, char* [])
 {
     test_type();
     test_approximation();
     test_formatting();
+ test_long_default_value();
     return 0;
 }


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