Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r86571 - in trunk: boost/program_options libs/program_options/src
From: ghost_at_[hidden]
Date: 2013-11-06 04:23:14


Author: vladimir_prus
Date: 2013-11-06 04:23:14 EST (Wed, 06 Nov 2013)
New Revision: 86571
URL: http://svn.boost.org/trac/boost/changeset/86571

Log:
Align columns across groups in --help output.

Patch from Leo Goodstadt.
Fixes #6114.

Text files modified:
   trunk/boost/program_options/options_description.hpp | 6 +++++-
   trunk/libs/program_options/src/options_description.cpp | 30 ++++++++++++++++++++++--------
   2 files changed, 27 insertions(+), 9 deletions(-)

Modified: trunk/boost/program_options/options_description.hpp
==============================================================================
--- trunk/boost/program_options/options_description.hpp Wed Nov 6 01:37:46 2013 (r86570)
+++ trunk/boost/program_options/options_description.hpp 2013-11-06 04:23:14 EST (Wed, 06 Nov 2013) (r86571)
@@ -199,6 +199,10 @@
         */
         options_description& add(const options_description& desc);
 
+ /** Find the maximum width of the option column, including options
+ in groups. */
+ unsigned get_option_column_width() const;
+
     public:
         /** Returns an object of implementation-defined type suitable for adding
             options to options_description. The returned object will
@@ -229,7 +233,7 @@
 
         /** Outputs 'desc' to the specified stream, calling 'f' to output each
             option_description element. */
- void print(std::ostream& os) const;
+ void print(std::ostream& os, unsigned width = 0) const;
 
     private:
         typedef std::map<std::string, int>::const_iterator name2index_iterator;

Modified: trunk/libs/program_options/src/options_description.cpp
==============================================================================
--- trunk/libs/program_options/src/options_description.cpp Wed Nov 6 01:37:46 2013 (r86570)
+++ trunk/libs/program_options/src/options_description.cpp 2013-11-06 04:23:14 EST (Wed, 06 Nov 2013) (r86571)
@@ -604,12 +604,9 @@
         }
     }
 
- void
- options_description::print(std::ostream& os) const
+ unsigned
+ options_description::get_option_column_width() const
     {
- if (!m_caption.empty())
- os << m_caption << ":\n";
-
         /* Find the maximum width of the option column */
         unsigned width(23);
         unsigned i; // vc6 has broken for loop scoping
@@ -620,6 +617,11 @@
             ss << " " << opt.format_name() << ' ' << opt.format_parameter();
             width = (max)(width, static_cast<unsigned>(ss.str().size()));
         }
+
+ /* Get width of groups as well*/
+ for (unsigned j = 0; j < groups.size(); ++j)
+ width = max(width, groups[j]->get_option_column_width());
+
         /* this is the column were description should start, if first
            column is longer, we go to a new line */
         const unsigned start_of_description_column = m_line_length - m_min_description_length;
@@ -628,9 +630,20 @@
         
         /* add an additional space to improve readability */
         ++width;
-
+ return width;
+ }
+
+ void
+ options_description::print(std::ostream& os, unsigned width) const
+ {
+ if (!m_caption.empty())
+ os << m_caption << ":\n";
+
+ if (!width)
+ width = get_option_column_width();
+
         /* The options formatting style is stolen from Subversion. */
- for (i = 0; i < m_options.size(); ++i)
+ for (unsigned i = 0; i < m_options.size(); ++i)
         {
             if (belong_to_group[i])
                 continue;
@@ -643,7 +656,8 @@
         }
 
         for (unsigned j = 0; j < groups.size(); ++j) {
- os << "\n" << *groups[j];
+ os << "\n";
+ groups[j]->print(os, width);
         }
     }
 


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