[issue22848] Subparser help does not respect SUPPRESS argument

paul j3 report at bugs.python.org
Fri Apr 17 06:23:13 CEST 2015


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 <report at bugs.python.org>
<http://bugs.python.org/issue22848>
_______________________________________


More information about the Python-bugs-list mailing list