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

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

问题描述

我正在构建一个 Python 包,并使用 Sphinx 创建文档.除了我的包代码,我还包含了很多命令行 Python 脚本,它们使用了 argparse.我想知道是否有办法让 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, let me know.

推荐答案

您可以使用 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天全站免登陆