0

Consider this arg_test.py script:

#!/usr/bin/env python3

import argparse

parser = argparse.ArgumentParser()
subparsers = parser.add_subparsers(help='subcommand help')

# create the parser for subcommand
parser_a = subparsers.add_parser('do-stuff', help='Help for do-stuff subcommand')

args = parser.parse_args()

With the help for the subcommand I get:

./arg_test.py do-stuff -h
usage: arg_test.py do-stuff [-h]

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

How can I add some usage description when using -h? For example I would like to get:

./arg_test.py do-stuff -h
usage: arg_test.py do-stuff [-h]

This subcommand does awsome stuff       << HOW DO I ADD THIS?

optional arguments:
  -h, --help  show this help message and exit
dariober
  • 8,240
  • 3
  • 30
  • 47
  • Did you had a look at: https://stackoverflow.com/questions/20094215/argparse-subparser-monolithic-help-output – Maurice Meyer Oct 21 '21 at 10:17
  • @MauriceMeyer I think that https://stackoverflow.com/questions/20094215/argparse-subparser-monolithic-help-output is more complex than what I need and I'm not sure it answers my question. I was hoping for a simple option that I've missed since printing the usage of a subcommand when that subcommand is invoked seems pretty reasonable to me... – dariober Oct 21 '21 at 10:33
  • The `add_parser` commend takes the same parameters as `ArgumentParser`, such as `description` and `epilog`. – hpaulj Oct 21 '21 at 10:36
  • @hpaulj indeed `description` is the option I needed - I don't know how I could have missed it... If you post that as an answer I'll accept it. – dariober Oct 21 '21 at 10:51

0 Answers0