Title: Allow grouping of argparse subparser commands in help output
Type: enhancement Stage: needs patch
Components: Library (Lib) Versions: Python 3.3
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: bethard, chris.jerdonek, ncoghlan, toszter
Priority: normal Keywords:

Created on 2012-02-16 23:46 by ncoghlan, last changed 2013-01-30 01:27 by chris.jerdonek.

Messages (2)
msg153514 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2012-02-16 23:46
I've just started using the argparse subparser feature, and it's very nice. However, I'd love to be able to group the different subparser commands into different sections the way I can group ordinary arguments with add_argument_group().

Initially I thought just calling "parser.add_subparsers()" multiple times with different "title" values would work, but argparse doesn't currently like that - it errors out with "cannot have multiple subparser arguments".

I propose that instead of treating this case as an error, argparse should treat it as a way for defining subparser groups - there would still only be a single subparser argument accepted, but the individual commands would appear grouped appropriately in the help output.
msg153517 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2012-02-16 23:54
I realised that my initial idea doesn't play nicely with my other suggestion of allowing a "metavar" argument to add_subparsers() (see #14039).

A better model may be to mimic the add_argument_group() directly by offering an add_parser_group() method on the subparser management object.

This would allow ungrouped commands to be presented first, with grouped commands following under their own headings.
Date User Action Args
2013-01-30 01:27:56chris.jerdoneksetnosy: + chris.jerdonek
2013-01-30 00:27:19tosztersetnosy: + toszter
2012-02-16 23:54:55ncoghlansetmessages: + msg153517
2012-02-16 23:46:45ncoghlancreate