argparse的--help是否可以显示我的退出状态?

JSt*_*oop 3 python argparse

我有一个用Python编写的实用程序,可以单独使用,也可以与其他shell实用程序一起使用.因此,我的实用程序退出状态代码(例如,0如果一切正常,1输入文件或输出目录不存在时等).

我的问题:我正在使用argparse模块,它工作得很好,不仅用于解析选项,还用于生成帮助.但是,我希望能够将有关退出状态的一些信息添加到帮助中.这有可能与argparse; 我错过了什么吗?

Rik*_*ggi 6

这是我在epilog中放入的信息.

调整官方文档中的示例:

>>> import argparse
>>> parser = argparse.ArgumentParser(
...     description='This is my utility description.',
...     epilog='The exit status will be 0 if everything is fine, '
...            'and 1 if an input-file or an output-directory does not exist')
>>> 
>>> parser.print_help()
usage: [-h]

This is my utility description.

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

The exit status will be 0 if everything is fine, and 1 when an input-file or
an output-directory does not exist
Run Code Online (Sandbox Code Playgroud)