Author paul.j3
Recipients bethard, gotgenes, micktwomey, paul.j3
Date 2013-07-15.03:51:39
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1373860302.88.0.85618712545.issue10984@psf.upfronthosting.co.za>
In-reply-to
Content
This patch adds a MultiGroupHelpFormatter that formats groups even if they share actions or the actions are not in the same order as in the parse._actions list.  It sorts the groups so positional actions, if any appear in the correct order.

A long test case generates this help:

    usage: PROG [-h] [-a A | -c C] [-a A | -d D] [-a A | -b B] [-b B | -d D]
                [-d D | x] foo [-b B | y]

    positional arguments:
      x           x help
      foo         foo help        
      y           y help

    optional arguments:
      -h, --help  show this help message and exit
      -a A        a help
      -b B        b help
      -c C        c help
      -d D        d help

In the 2nd usage line, the 2 groups, and action foo, are shown in the order in which x, foo, y were defined (and hence will be parsed), even though the groups were not defined in that order.

The default formatter could not format these groups, generating '[-h] [-a A] [-b B] ... x foo y' instead.

I have included the latest patch from http://bugs.python.org/issue11874.  This splits the usage line generated by _format_actions_usage into parts that are groups or independent actions.  The goal there is to correctly split long usage lines into multiple lines.  Here it makes it easier to format groups and actions in new order.

If existing actions are added to new group as in the original patch for this issue, that group gets a no_usage = True attribute.  The default formatter then will not attempt to format this group. The MultiGroupHelpFormatter ignores this attribute.

This patch needs better documentation. Test cases also need refinement, improving the names, and eliminating redundancies.  Some of the new tests are copies of existing ones, but using the new formatter.
History
Date User Action Args
2013-07-15 03:51:43paul.j3setrecipients: + paul.j3, bethard, gotgenes, micktwomey
2013-07-15 03:51:42paul.j3setmessageid: <1373860302.88.0.85618712545.issue10984@psf.upfronthosting.co.za>
2013-07-15 03:51:42paul.j3linkissue10984 messages
2013-07-15 03:51:42paul.j3create