Author paul.j3
Recipients bethard, gotgenes, micktwomey, paul.j3
Date 2013-09-17.05:05:58
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1379394358.48.0.0521882559471.issue10984@psf.upfronthosting.co.za>
In-reply-to
Content
Another situation in which this MultiGroupHelpFormatter helps is when one or more of the groups includes an optional positional.  

The regular formatter moves all the positionals to the end, after the optionals.  This move could easily break up a mutually exclusive group, and make formatting it impossible.  But the MultiGroupHelpFormatter gives the group order priority.

Thus for example:

    p=argparse.ArgumentParser()
    # (formatter_class=argparse.MultiGroupHelpFormatter)
    g=p.add_mutually_exclusive_group()
    g.add_argument('-f')
    g.add_argument('foo',nargs='?')
    g=p.add_mutually_exclusive_group()
    g.add_argument('-b')
    g.add_argument('-c')
    g.add_argument('bar',nargs='*',default='X')
    print(p.format_usage())

produces (positionals at end, no group markings)

    usage: PROG [-h] [-f F] [-b B] [-c C] [foo] [bar [bar ...]]

But the MultiGroupHelpFormatter produces:

    usage: PROG [-h] [-f F | foo] [-b B | -c C | bar [bar ...]]

In this last case, the positionals are listed with their respective groups, and the groups are ordered by the relative ordering of the positionals.
History
Date User Action Args
2013-09-17 05:05:58paul.j3setrecipients: + paul.j3, bethard, gotgenes, micktwomey
2013-09-17 05:05:58paul.j3setmessageid: <1379394358.48.0.0521882559471.issue10984@psf.upfronthosting.co.za>
2013-09-17 05:05:58paul.j3linkissue10984 messages
2013-09-17 05:05:58paul.j3create