Message241310
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. |
|
Date |
User |
Action |
Args |
2015-04-17 04:23:13 | paul.j3 | set | recipients:
+ paul.j3, barry, bethard, r.david.murray, derks, mattlong, Brett.Hannigan |
2015-04-17 04:23:13 | paul.j3 | set | messageid: <1429244593.6.0.924636331913.issue22848@psf.upfronthosting.co.za> |
2015-04-17 04:23:13 | paul.j3 | link | issue22848 messages |
2015-04-17 04:23:13 | paul.j3 | create | |
|