Sphinx和argparse-自动记录命令行脚本吗? [英] Sphinx and argparse - autodocumenting command line scripts?

查看:65
本文介绍了Sphinx和argparse-自动记录命令行脚本吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个Python包,并使用Sphinx创建文档.除了我的程序包代码外,我还包括许多使用argparse的命令行Python脚本.我想知道是否有办法让Sphinx自动记录这些脚本?最终目标将是漂亮打印的脚本列表,以及相关的帮助打印,参数和选项.而且要明确一点,我正在寻找一种预先存在的方式来执行此操作,而不是自己实现此方式.

I'm building a Python package, and using Sphinx to create the docs. Aside from my package code, I also include a lot of command line Python scripts, which use argparse. I was wondering if there is a way to get Sphinx to autodocument these scripts? The end goal would be a pretty-printed list of scripts, with the associated help print, arguments and options. And to be clear, I'm looking for a pre-existing way to do this, not a way to implement this myself.

这个问题不像我通常在S.O.上问的那样具体,如果有更合适的S.E.网站上发布此问题,请让我知道.谢谢.

This isn't as specific of a question as I usually ask on S.O., if there is a more appropriate S.E. site to post this question, please let me know. Thanks.

推荐答案

您可以使用 sphinxcontrib.programoutput 包括文档中命令行中的帮助消息.

You can use sphinxcontrib.programoutput to include the help messages from the command line in your documentation.

这不是argparse所特有的,但可用于将任何脚本打印帮助消息记录到命令行.

This is not specific to argparse but can be used to document any script printing help messages to the command line.

这篇关于Sphinx和argparse-自动记录命令行脚本吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆