Skip to content

Make argparse print description of subcommand when invoke help doc on subcommand #89438

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
longendu mannequin opened this issue Sep 24, 2021 · 6 comments
Closed

Make argparse print description of subcommand when invoke help doc on subcommand #89438

longendu mannequin opened this issue Sep 24, 2021 · 6 comments
Labels
3.11 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@longendu
Copy link
Mannequin

longendu mannequin commented Sep 24, 2021

BPO 45275
Nosy @shihai1991, @sobolevn, @akulakov
Files
  • Selection_011.png
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = None
    created_at = <Date 2021-09-24.04:32:20.243>
    labels = ['type-feature', 'library', '3.11']
    title = 'Make argparse print description of subcommand when invoke help doc on subcommand'
    updated_at = <Date 2021-10-25.16:39:19.615>
    user = 'https://bugs.python.org/longendu'

    bugs.python.org fields:

    activity = <Date 2021-10-25.16:39:19.615>
    actor = 'paul.j3'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2021-09-24.04:32:20.243>
    creator = 'longendu'
    dependencies = []
    files = ['50301']
    hgrepos = []
    issue_num = 45275
    keywords = []
    message_count = 5.0
    messages = ['402541', '402607', '404880', '404932', '404983']
    nosy_count = 5.0
    nosy_names = ['paul.j3', 'shihai1991', 'sobolevn', 'andrei.avk', 'longendu']
    pr_nums = []
    priority = 'normal'
    resolution = None
    stage = None
    status = 'open'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue45275'
    versions = ['Python 3.11']

    @longendu
    Copy link
    Mannequin Author

    longendu mannequin commented Sep 24, 2021

    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.

    @longendu longendu mannequin added 3.7 (EOL) end of life 3.8 (EOL) end of life 3.9 only security fixes 3.10 only security fixes 3.11 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels Sep 24, 2021
    @terryjreedy terryjreedy removed 3.7 (EOL) end of life 3.8 (EOL) end of life 3.9 only security fixes 3.10 only security fixes labels Sep 25, 2021
    @sobolevn
    Copy link
    Member

    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?

    @akulakov
    Copy link
    Contributor

    For me it works as well, tested on 3.7, 3.9 and 3.11 .

    @shihai1991
    Copy link
    Member

    Hi, Chuanlong. Would you mind to upload a demo for this question?

    @paulj3
    Copy link
    Mannequin

    paulj3 mannequin commented Oct 25, 2021

    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.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    @erlend-aasland erlend-aasland moved this to Features in Argparse issues May 19, 2022
    @serhiy-storchaka serhiy-storchaka closed this as not planned Won't fix, can't repro, duplicate, stale Sep 27, 2024
    @github-project-automation github-project-automation bot moved this from Features to Doc issues in Argparse issues Sep 27, 2024
    @serhiy-storchaka
    Copy link
    Member

    Closed as the requested feature already exists in argparse.

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.11 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    Status: Doc issues
    Development

    No branches or pull requests

    5 participants