paul j3 added the comment:

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.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue22848>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to