This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author paul.j3
Recipients Brett.Hannigan, barry, bethard, derks, mattlong, paul.j3, r.david.murray
Date 2015-04-17.04:23:13
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1429244593.6.0.924636331913.issue22848@psf.upfronthosting.co.za>
In-reply-to
Content
Giving the `subparsers` Action a `metavar` might achieve everything the proposed patch does - without any code changes.

In the 1st test case:

    subparsers = parser.add_subparsers(title='subcommands',
                                           description='subcommands description',
                                           help='subcommands help',
                                           metavar='{1,2}')

and for the 2nd

    parser = argparse.ArgumentParser(prog='PROG_ALL',
                                            description='main description')
    subparsers = parser.add_subparsers(title='subcommands',
                                           description='subcommands description',
                                           help='subcommands help',
                                           metavar='{}')
    parser1 = subparsers.add_parser('1')  # no help
    parser2 = subparsers.add_parser('2', aliases=('2alias',))


Note that neither the patch nor the metavar affects how the choices are displayed in an error message, e.g.

    usage: PROG [-h] {} ...
    PROG: error: argument {}: invalid choice: 'foo' (choose from '1', '2', '2alias')

For more discussion on formatting of choices see http://bugs.python.org/issue16468


--------------------

While I'll continue to think about this issue, my tentative suggestion is to make this a documentation fix, rather than a code change.  Just let users know that `add_subparsers` takes a `metavar` parameter, just like `add_argument`.  It can hide or otherwise customize the listing of commands.
History
Date User Action Args
2015-04-17 04:23:13paul.j3setrecipients: + paul.j3, barry, bethard, r.david.murray, derks, mattlong, Brett.Hannigan
2015-04-17 04:23:13paul.j3setmessageid: <1429244593.6.0.924636331913.issue22848@psf.upfronthosting.co.za>
2015-04-17 04:23:13paul.j3linkissue22848 messages
2015-04-17 04:23:13paul.j3create