像在 python 上一样打印 linux man-help
我正在尝试像 Linux man 那样为我的自定义应用程序构建帮助消息输出。我一直在使用 pprint、使用字典等。但是,我有点失落。我目前正在使用字典与打印命令相结合。到目前为止已经足够满足我的需求了,但我必须承认它还没有达到标准。
我想使用 flags 命令样式,我的意思是 -f 、 -t 等。我认为建立的目的是使用解析器或类似的东西提取数据。
那么,简而言之,你们如何构建帮助消息以正确使用基于命令的应用程序?
I am trying to build a help message output for my custom app like Linux man does. I've been walking around pprint, using dictionaries, and others. But, I'm al little lost. I'm currently using a dictionary combined with print commands. Until now is enough for my needs but I must confess It's not up to scratch.
I would like to use the flags command style, I mean, -f , -t , etc. I supose that the point of establish is to extract data using a parser o something like that.
So, in a few words, How do you guys build help messages for the properly usage of your command based apps?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
optparse
和argparse
都支持打印使用详细信息。optparse
andargparse
both support printing usage details.有 optparse 模块及其后继 argparse (第一个自 Python 2.7 起已弃用)。这些模块自动生成如下所示的帮助输出(来自 Python 文档):
There's the optparse module, and its successor argparse (the first one is deprecated since Python 2.7). These modules automatically generate help output like this one (from the Python docs):