classification
Title: allow argparse subcommands to be grouped
Type: enhancement Stage: needs patch
Components: Library (Lib) Versions: Python 3.5, Python 2.7
process
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 2014-07-15 22:52 by paul.j3.

Files
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 http://code.google.com/p/argparse/issues/detail?id=53]

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

subcommands:
  {a,b,c,d,e}
    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:

subcommands:
  group1:
    a          a subcommand help
    b          b subcommand help
    c          c subcommand help
  group2:
    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 http://bugs.python.org/issue16807
History
Date User Action Args
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