Opened 11 years ago

Closed 9 years ago

Last modified 9 years ago

#6114 closed Patches (fixed)

Program options help message do not align across multiple groups

Reported by: Leo Goodstadt <boost@…> Owned by: Vladimir Prus
Milestone: To Be Determined Component: program_options
Version: Boost 1.47.0 Severity: Problem
Keywords: Program options help description Cc:

Description

libs/program_options/src/options_description.cpp contains code to line up the description strings if the length of the options column > 23.

However, this does not take different groups into account. The patch gets the column lengths from the subgroups as well.

Current situation:

Overall:

Option group 1:
  --opt1                Short option 1
  --option 2            Short option 2
                        ^
                        Aligned here

Option group 2:
  --much_longer_option arg Misaligned description in 2nd group if option column
                           length > magic 23 character limit
                           ^
                           Aligned here

Patched:

Overall:

Option group 1:
  --opt1                    Short option 1
  --option 2                Short option 2
                            ^
                            Aligned here

Option group 2:
  --much_longer_option arg  Misaligned description in 2nd group if option 
                            column length > magic 23 character limit
                            ^
                            Aligned here

is produced by this minimal program

#include <iostream>
#include <boost/program_options.hpp>
namespace po = boost::program_options;

int main (int argc, char *argv[])
{
    // 1st group
    po::options_description groups1 ("Option group 1");
    groups1.add_options()
        ("opt1",     "Short option 1")
        ("option 2", "Short option 2\n^\nAligned here");

    // 2nd group
    po::options_description groups2 ("Option group 2");
    groups2.add_options()
      ("much_longer_option", po::value<int>(), 
           "Misaligned description in 2nd group if option "
           "column length > magic 23 character limit\n^\n"
           "Aligned here");


    po::options_description cmdline_args("Overall");
    cmdline_args.add(groups1);
    cmdline_args.add(groups2);
    std::cerr << cmdline_args << "\n";

    return 0;
}

Attachments (2)

main.cpp (815 bytes ) - added by Leo Goodstadt <boost@…> 11 years ago.
test case
svn_diff.txt (3.2 KB ) - added by Leo Goodstadt <boost@…> 11 years ago.
patch

Download all attachments as: .zip

Change History (7)

by Leo Goodstadt <boost@…>, 11 years ago

Attachment: main.cpp added

test case

by Leo Goodstadt <boost@…>, 11 years ago

Attachment: svn_diff.txt added

patch

comment:1 by boost@…, 10 years ago

This "bug" seems to be still present on boost 1.49.0. It would be great if this patch could be checked / pushed by someone. It's not a major issue to have unaligned options but still, it would looks much better if they were.

comment:2 by TonyELewis@…, 9 years ago

I would also really appreciate someone qualified assessing this relatively simple patch because this issue is making my Boost.Program_options (1.54.0) interface look much less professional. Thanks very much.

comment:3 by Vladimir Prus, 9 years ago

Resolution: fixed
Status: newclosed

(In [86571]) Align columns across groups in --help output.

Patch from Leo Goodstadt. Fixes #6114.

comment:4 by Vladimir Prus, 9 years ago

I've checked in to trunk, sorry it took so long, and also for missing 1.55 release.

I've set a reminder to merge to release branch, although I don't know what that would mean in the git world, but hopefully will figure out.

comment:5 by TonyELewis@…, 9 years ago

Fantastic! Thank you very much.

Note: See TracTickets for help on using tickets.