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.

Title: allow argparse subcommands to be grouped
Type: enhancement Stage: needs patch
Components: Library (Lib) Versions: Python 3.5, Python 2.7
Status: open Resolution: accepted
Dependencies: Superseder:
Assigned To: Nosy List: bethard, eric.araujo, paul.j3, pconnell
Priority: normal Keywords: patch

Created on 2010-07-23 12:17 by bethard, last changed 2022-04-11 14:57 by admin.

File name Uploaded Description Edit
issue9341_1.patch paul.j3, 2014-06-22 19:37 review
Messages (3)
msg111290 - (view) Author: Steven Bethard (bethard) * (Python committer) Date: 2010-07-23 12:17
[Moved from]

It's currently not possible to have subcommands formatted in groups, e.g. instead of:

    a          a subcommand help
    b          b subcommand help
    c          c subcommand help
    d          d subcommand help
    e          e subcommand help 

you should be able to get something like:

    a          a subcommand help
    b          b subcommand help
    c          c subcommand help
    d          d subcommand help
    e          e subcommand help
msg221297 - (view) Author: paul j3 (paul.j3) * (Python triager) Date: 2014-06-22 19:37
This patch accomplishes this task by adding a  _PseudoGroup class to _SubParsersAction.  It's like the _ChoicesPseudoAction except that it maintains its own _choices_actions list.

It takes advantage of the fact that formatter._format_actions is recursive when it comes to actions in _choices_actions.  In fact it is possible to define groups within groups (not that I would recommend that).

There is one simple test case in test_argparse, similar to the example in this issue.
msg223155 - (view) Author: paul j3 (paul.j3) * (Python triager) Date: 2014-07-15 22:52
This patch probably won't work with [parents].  see
Date User Action Args
2022-04-11 14:57:04adminsetgithub: 53587
2014-07-15 22:52:41paul.j3setmessages: + msg223155
2014-06-22 19:37:06paul.j3setfiles: + issue9341_1.patch
keywords: + patch
messages: + msg221297
2014-06-16 21:56:17BreamoreBoysetnosy: + paul.j3

versions: + Python 2.7, Python 3.5, - Python 3.2
2013-04-13 17:35:26pconnellsetnosy: + pconnell
2010-07-23 12:40:30eric.araujosetnosy: + eric.araujo

resolution: accepted
versions: + Python 3.2
2010-07-23 12:17:29bethardcreate