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.

classification
Title: Make argparse print description of subcommand when invoke help doc on subcommand
Type: enhancement Stage:
Components: Library (Lib) Versions: Python 3.11
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: andrei.avk, longendu, paul.j3, shihai1991, sobolevn
Priority: normal Keywords:

Created on 2021-09-24 04:32 by longendu, last changed 2022-04-11 14:59 by admin.

Files
File name Uploaded Description Edit
Selection_011.png longendu, 2021-09-24 04:32
Messages (5)
msg402541 - (view) Author: Chuanlong Du (longendu) Date: 2021-09-24 04:32
I have command-line script `blog` written using argparse. It supports subcommands. When I check the help doc of a subcommand, e.g., using `blog convert -h`, it prints the help doc of the subcommand `blog convert` but doesn't print the description of the subcommand `blog convert`. A screenshot is attached. It is quite often that I know a command-line application have certain subcommands but I forget exactly what they do. It would be very helpful if `blog subcmd -h` prints the description of the subcmd so that users do not have to call `blog -h` again to check exactly what the subcommand does.
msg402607 - (view) Author: Nikita Sobolev (sobolevn) * (Python triager) Date: 2021-09-25 07:43
Hi!

From your description it is not clear how exactly you create your subcommand.

From my experience, it works. Demo:

```
import argparse

parser = argparse.ArgumentParser(description='Process some integers.')
subparsers = parser.add_subparsers()

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

print(parser.parse_args())
```

Here's the output of `python script.py a -h`:

```
usage: ex.py a [-h] bar

test me

positional arguments:
  bar         bar help

options:
  -h, --help  show this help message and exit
```

Do you have the same setup? Or is there anything else that needs to be fixed?
msg404880 - (view) Author: Andrei Kulakov (andrei.avk) * (Python triager) Date: 2021-10-23 15:18
For me it works as well, tested on 3.7, 3.9 and 3.11 .
msg404932 - (view) Author: Hai Shi (shihai1991) * (Python triager) Date: 2021-10-24 13:33
Hi, Chuanlong. Would you mind to upload a demo for this question?
msg404983 - (view) Author: paul j3 (paul.j3) * (Python triager) Date: 2021-10-25 16:39
Are you expecting the subcommand help to show the 'help' line that the main help shows?

    subparsers.add_parser('a', help='a help')

add_parser takes all of the parameters that `ArgumentParser` takes, including description and epilog.  

I don't think we need to add anything to add_parser.
History
Date User Action Args
2022-04-11 14:59:50adminsetgithub: 89438
2021-10-25 16:39:19paul.j3setnosy: + paul.j3
messages: + msg404983
2021-10-24 13:33:27shihai1991setnosy: + shihai1991
messages: + msg404932
2021-10-23 15:18:35andrei.avksetnosy: + andrei.avk
messages: + msg404880
2021-09-25 07:43:05sobolevnsetnosy: + sobolevn
messages: + msg402607
2021-09-25 00:09:00terry.reedysetversions: - Python 3.6, Python 3.7, Python 3.8, Python 3.9, Python 3.10
2021-09-24 04:32:20longenducreate