如何使用Sphinx来记录Bash脚本?

5

我刚开始使用Sphinx(sphinx-doc.org)来记录一个Python项目。到目前为止,它工作得很好,我能够记录和自动记录我的Python代码。

该项目还包含几个bash脚本。我想使用自动文档记录这些bash脚本。我没有找到特定于bash脚本的域。所以我猜想必须使用标准域

如果可能的话,你会如何做到这一点?我需要如何配置index.rst文件以及如何在bash脚本中使用reStructuredText?


Autodoc仅适用于Python模块。Sphinx没有类似的功能来处理Bash脚本。 - mzjn
1个回答

1
这里是您请求的示例。我在我的source_suffix中使用.rst,但您可以在您网站的conf.py中更改它。请注意,我将bash文件命名为test.sh.rst以便提醒自己它是一个bash文件。只要您使用chmod +x设置了mod,Linux就不会在意文件名是什么。
index.rst 示例:
.. _MyManual:

My Manual
===========================================

.. toctree::
   :maxdepth: 2
   :caption: Contents:

   doc/doc
   bash/test.sh

示例 test.sh.rst:

#!/bin/bash
: '

***********************
Example Bash
***********************

Using multi-line comment for larger comments. 

And use hash # to proceed code so it shows nicely in sphinx. Note the double 
:: at the end to give the proper formatting. 

'

# Initial code::

    mkdir tmp

# check_client::

   check_client()
   {
   # determine if this is being run on a client that is using git folder
   # check the parameter for the bash on CLI and if exist, use it
   echo HERE in client "$1" and "$parameter_1"
   if [[ "$parameter_1" = "" ]]; then
      client_directory=/
   else
      client_directory=/git
   fi
   }

# other code::

   parameter_1="$1"
   check_client
   echo the client is "$client_directory"

   read -p "pause " answer

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接