Sphinx and argparse - autodocumenting command line scripts?

后端 未结 3 1514
失恋的感觉
失恋的感觉 2020-12-15 16:56

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 w

相关标签:
3条回答
  • 2020-12-15 17:39

    You can use sphinxcontrib.autoprogram. pip install sphinxcontrib-autoprogram, then put

    extensions += ['sphinxcontrib.autoprogram']
    

    in your conf.py. To document command cli.py by importing cli with the argparse parser object parser (which can be a Python expression, like a function get_parser()), use

    .. autoprogram:: cli:parser
       :prog: cli.py
    
    0 讨论(0)
  • 2020-12-15 17:40

    Use sphinx-argparse extension:

    http://sphinx-argparse.readthedocs.org/en/latest/

    0 讨论(0)
  • 2020-12-15 17:53

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

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

    0 讨论(0)
提交回复
热议问题