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 Martin.d'Anjou
Recipients Martin.d'Anjou
Date 2014-01-21.16:46:08
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1390322768.82.0.0490461606421.issue20333@psf.upfronthosting.co.za>
In-reply-to
Content
Consider the following code:

#!/usr/bin/env python3
import argparse

# create the top-level parser
parser = argparse.ArgumentParser(prog='PROG')
parser.add_argument('--file', help='A filename', required=True)
subparsers = parser.add_subparsers(help='sub-command help')

# create the parser for the "a" command
parser_a = subparsers.add_parser('a', help='a help')
parser_a.add_argument('bar', type=int, help='bar help')

# create the parser for the "b" command
parser_b = subparsers.add_parser('b', help='b help')
parser_b.add_argument('--baz', choices='XYZ', help='baz help')

The help for subparser a is obtained with: parser.parse_args(["a","--help"])

usage: PROG a [-h] bar

positional arguments:
  bar         bar help

optional arguments:
  -h, --help  show this help message and exit

When the user follows the help, the user gets it wrong:
parser.parse_args(["a","10"])

usage: PROG [-h] --file FILE {a,b} ...
PROG: error: argument --file is required

The correct way to use the subparser is:
parser.parse_args(["--file","file","a","10"])

But the problem is that the original help message is not telling the user that this is the correct way. When asking for the "a" subparser help, the usage message should also reveal the main parser arguments. Continuing with the example, something like this should be appropriate:

usage: PROG [-h] --file FILE a [-h] bar

This is how the argparse Java port works.
History
Date User Action Args
2014-01-21 16:46:08Martin.d'Anjousetrecipients: + Martin.d'Anjou
2014-01-21 16:46:08Martin.d'Anjousetmessageid: <1390322768.82.0.0490461606421.issue20333@psf.upfronthosting.co.za>
2014-01-21 16:46:08Martin.d'Anjoulinkissue20333 messages
2014-01-21 16:46:08Martin.d'Anjoucreate