I am using argparse.ArgumentParser() in my script, I would like to display the pydoc description of my script as part of the '--help' option of the argparse.
One possibly solution can be to use the formatter_class or the description attribute of ArgumentParser to configure the displaying of help. But in this case, we need to use the 'pydoc' command internally to fetch the description.
Do we have some other ways (possibly elegant) to do it?
You can retrieve the docstring of your script from the
__doc__global. To add it to your script's help, you can set thedescriptionargument of the parser.Then the help will look like:
You can use the
epilogkeyword argument instead ofdescriptionto move the docstring to the end of the help, instead of immediately following the usage string.