@@ -604,12 +604,9 @@ namespace boost { namespace program_options {
604
604
}
605
605
}
606
606
607
- void
608
- options_description::print (std::ostream& os ) const
607
+ unsigned
608
+ options_description::get_option_column_width ( ) const
609
609
{
610
- if (!m_caption.empty ())
611
- os << m_caption << " :\n " ;
612
-
613
610
/* Find the maximum width of the option column */
614
611
unsigned width (23 );
615
612
unsigned i; // vc6 has broken for loop scoping
@@ -620,6 +617,11 @@ namespace boost { namespace program_options {
620
617
ss << " " << opt.format_name () << ' ' << opt.format_parameter ();
621
618
width = (max)(width, static_cast <unsigned >(ss.str ().size ()));
622
619
}
620
+
621
+ /* Get width of groups as well*/
622
+ for (unsigned j = 0 ; j < groups.size (); ++j)
623
+ width = max (width, groups[j]->get_option_column_width ());
624
+
623
625
/* this is the column were description should start, if first
624
626
column is longer, we go to a new line */
625
627
const unsigned start_of_description_column = m_line_length - m_min_description_length;
@@ -628,9 +630,20 @@ namespace boost { namespace program_options {
628
630
629
631
/* add an additional space to improve readability */
630
632
++width;
631
-
633
+ return width;
634
+ }
635
+
636
+ void
637
+ options_description::print (std::ostream& os, unsigned width) const
638
+ {
639
+ if (!m_caption.empty ())
640
+ os << m_caption << " :\n " ;
641
+
642
+ if (!width)
643
+ width = get_option_column_width ();
644
+
632
645
/* The options formatting style is stolen from Subversion. */
633
- for (i = 0 ; i < m_options.size (); ++i)
646
+ for (unsigned i = 0 ; i < m_options.size (); ++i)
634
647
{
635
648
if (belong_to_group[i])
636
649
continue ;
@@ -643,7 +656,8 @@ namespace boost { namespace program_options {
643
656
}
644
657
645
658
for (unsigned j = 0 ; j < groups.size (); ++j) {
646
- os << " \n " << *groups[j];
659
+ os << " \n " ;
660
+ groups[j]->print (os, width);
647
661
}
648
662
}
649
663
0 commit comments