| 1 | Index: boost/program_options/options_description.hpp
|
|---|
| 2 | ===================================================================
|
|---|
| 3 | --- boost/program_options/options_description.hpp (revision 75427)
|
|---|
| 4 | +++ boost/program_options/options_description.hpp (working copy)
|
|---|
| 5 | @@ -189,6 +189,10 @@
|
|---|
| 6 | */
|
|---|
| 7 | options_description& add(const options_description& desc);
|
|---|
| 8 |
|
|---|
| 9 | + /** Find the maximum width of the option column, including options in groups
|
|---|
| 10 | + */
|
|---|
| 11 | + unsigned get_option_column_width() const;
|
|---|
| 12 | +
|
|---|
| 13 | public:
|
|---|
| 14 | /** Returns an object of implementation-defined type suitable for adding
|
|---|
| 15 | options to options_description. The returned object will
|
|---|
| 16 | @@ -219,8 +223,10 @@
|
|---|
| 17 |
|
|---|
| 18 | /** Outputs 'desc' to the specified stream, calling 'f' to output each
|
|---|
| 19 | option_description element. */
|
|---|
| 20 | - void print(std::ostream& os) const;
|
|---|
| 21 | + void print(std::ostream& os, unsigned width = 0) const;
|
|---|
| 22 |
|
|---|
| 23 | +
|
|---|
| 24 | +
|
|---|
| 25 | private:
|
|---|
| 26 | typedef std::map<std::string, int>::const_iterator name2index_iterator;
|
|---|
| 27 | typedef std::pair<name2index_iterator, name2index_iterator>
|
|---|
| 28 | Index: libs/program_options/src/options_description.cpp
|
|---|
| 29 | ===================================================================
|
|---|
| 30 | --- libs/program_options/src/options_description.cpp (revision 75427)
|
|---|
| 31 | +++ libs/program_options/src/options_description.cpp (working copy)
|
|---|
| 32 | @@ -581,12 +581,9 @@
|
|---|
| 33 | }
|
|---|
| 34 | }
|
|---|
| 35 |
|
|---|
| 36 | - void
|
|---|
| 37 | - options_description::print(std::ostream& os) const
|
|---|
| 38 | + unsigned
|
|---|
| 39 | + options_description::get_option_column_width() const
|
|---|
| 40 | {
|
|---|
| 41 | - if (!m_caption.empty())
|
|---|
| 42 | - os << m_caption << ":\n";
|
|---|
| 43 | -
|
|---|
| 44 | /* Find the maximum width of the option column */
|
|---|
| 45 | unsigned width(23);
|
|---|
| 46 | unsigned i; // vc6 has broken for loop scoping
|
|---|
| 47 | @@ -597,6 +594,11 @@
|
|---|
| 48 | ss << " " << opt.format_name() << ' ' << opt.format_parameter();
|
|---|
| 49 | width = (max)(width, static_cast<unsigned>(ss.str().size()));
|
|---|
| 50 | }
|
|---|
| 51 | +
|
|---|
| 52 | + /* Get width of groups as well*/
|
|---|
| 53 | + for (unsigned j = 0; j < groups.size(); ++j)
|
|---|
| 54 | + width =max(width, groups[j]->get_option_column_width());
|
|---|
| 55 | +
|
|---|
| 56 | /* this is the column were description should start, if first
|
|---|
| 57 | column is longer, we go to a new line */
|
|---|
| 58 | const unsigned start_of_description_column = m_line_length - m_min_description_length;
|
|---|
| 59 | @@ -605,6 +607,18 @@
|
|---|
| 60 |
|
|---|
| 61 | /* add an additional space to improve readability */
|
|---|
| 62 | ++width;
|
|---|
| 63 | + return width;
|
|---|
| 64 | + }
|
|---|
| 65 | +
|
|---|
| 66 | + void
|
|---|
| 67 | + options_description::print(std::ostream& os, unsigned width) const
|
|---|
| 68 | + {
|
|---|
| 69 | + if (!m_caption.empty())
|
|---|
| 70 | + os << m_caption << ":\n";
|
|---|
| 71 | +
|
|---|
| 72 | + if (!width)
|
|---|
| 73 | + width = get_option_column_width();
|
|---|
| 74 | +
|
|---|
| 75 |
|
|---|
| 76 | /* The options formatting style is stolen from Subversion. */
|
|---|
| 77 | for (i = 0; i < m_options.size(); ++i)
|
|---|
| 78 | @@ -620,7 +634,8 @@
|
|---|
| 79 | }
|
|---|
| 80 |
|
|---|
| 81 | for (unsigned j = 0; j < groups.size(); ++j) {
|
|---|
| 82 | - os << "\n" << *groups[j];
|
|---|
| 83 | + os << "\n";
|
|---|
| 84 | + groups[j]->print(os, width);
|
|---|
| 85 | }
|
|---|
| 86 | }
|
|---|
| 87 |
|
|---|