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.

Author paul.j3
Recipients Martin.d'Anjou, bethard, paul.j3
Date 2014-05-09.21:27:12
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1399670833.12.0.0376706978903.issue20333@psf.upfronthosting.co.za>
In-reply-to
Content
When `add_subparsers` creates the `_prog_prefix` it uses a list of positionals.  That makes sense, since a subparser argument is positional, so the user needs to know where it fits in the broader scope of positionals.

But it intentionally skips the 'optionals'.  The problem in the example for this bug is that its 'optional' is 'required'.  A fix is to include all 'required optionals' along with positionals in the usage prefix.  

Attached is a partial patch that does this.  

I also question whether it makes sense to include 'mutually_exclusive_groups' in this usage formatting, since all actions in such a group must be non-required.  And such a group can include at most one positional (with ? or *).  A MXG is marked only if all of its actions are present in the usage list.

The programmer can also customize the subparsers usage with the 'prog' keyword of either the 'add_subparsers' or 'add_parser' commands.  I illustrate this in the attached 'sample.py' script.

'test_argparse.py' does not seem to test this issue much.  Atleast it isn't bothered by these tweaks.

Note that any arguments added to the main parser after the 'add_subparsers' command will not appear the subparser usage, since this is defined when the subparsers are created.
History
Date User Action Args
2014-05-09 21:27:13paul.j3setrecipients: + paul.j3, bethard, Martin.d'Anjou
2014-05-09 21:27:13paul.j3setmessageid: <1399670833.12.0.0376706978903.issue20333@psf.upfronthosting.co.za>
2014-05-09 21:27:13paul.j3linkissue20333 messages
2014-05-09 21:27:12paul.j3create