Skip to main content

render CLI arguments (sub-commands friendly) defined by argparse module

Project description

sphinx-argparse-cli

PyPI PyPI - Implementation PyPI - Python Version PyPI - Downloads PyPI - License check Code style: black

Render CLI arguments (sub-commands friendly) defined by the argparse module. For live demo checkout the documentation of tox, python-build and mdpo.

installation

python -m pip install sphinx-argparse-cli

enable in your conf.py

# just add it to your list of extensions to load within conf.py
extensions = ["sphinx_argparse_cli"]

use

Within the reStructuredText files use the sphinx_argparse_cli directive that takes, at least, two arguments:

Name Description
module the module path to where the parser is defined
func the name of the function that once called with no arguments constructs the parser
prog (optional) the module path to where the parser is defined
title (optional) when provided, overwrites the <prog> - CLI interface title added by default and when empty, will not be included
usage_width (optional) how large should usage examples be - defaults to 100 character
group_title_prefix (optional) groups subsections title prefixes, accepts the string {prog} as a replacement for the program name - defaults to {prog}
group_sub_title_prefix (optional) subcommands groups subsections title prefixes, accepts replacement of {prog} and {subcommand} for program and subcommand name - defaults to {prog} {subcommand}

For example:

.. sphinx_argparse_cli::
  :module: a_project.cli
  :func: build_parser
  :prog: my-cli-program

Refer to generated content

The tool will register reference links to all anchors. This means that you can use the sphinx ref role to refer to both the (sub)command title/groups and every flag/argument. The tool offers a configuration flag sphinx_argparse_cli_prefix_document (change by setting this variable in conf.py - by default False). This option influences the reference ids generated. If it's false the reference will be the anchor id (the text appearing after the '# in the URI once you click on it). If it's true the anchor id will be prefixed by the document name (this is useful to avoid reference label clash when the same anchors are generated in multiple documents).

For example in case of a tox command, and sphinx_argparse_cli_prefix_document=False (default):

  • to refer to the optional arguments group use :ref:`tox-optional-arguments` ,
  • to refer to the run subcommand use :ref:`tox-run` ,
  • to refer to flag --magic of the run sub-command use :ref:`tox-run---magic` .

For example in case of a tox command, and sphinx_argparse_cli_prefix_document=True, and the current document name being cli:

  • to refer to the optional arguments group use :ref:`cli:tox-optional-arguments` ,
  • to refer to the run subcommand use :ref:`cli:tox-run` ,
  • to refer to flag --magic of the run sub-command use :ref:`cli:tox-run---magic` .

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sphinx_argparse_cli-1.8.0.tar.gz (21.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sphinx_argparse_cli-1.8.0-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file sphinx_argparse_cli-1.8.0.tar.gz.

File metadata

  • Download URL: sphinx_argparse_cli-1.8.0.tar.gz
  • Upload date:
  • Size: 21.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for sphinx_argparse_cli-1.8.0.tar.gz
Algorithm Hash digest
SHA256 7f0633614c0eab5eba69c23e29f36c451c4b5cce16bab2dc4c330bcf8f3180fd
MD5 e7f2a715a96f9cd8c32db8df671dfeff
BLAKE2b-256 45586aa70c50d7ffb4deef2e7b928b59c788ada0fd36b90127cfc70244388d19

See more details on using hashes here.

File details

Details for the file sphinx_argparse_cli-1.8.0-py3-none-any.whl.

File metadata

  • Download URL: sphinx_argparse_cli-1.8.0-py3-none-any.whl
  • Upload date:
  • Size: 8.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for sphinx_argparse_cli-1.8.0-py3-none-any.whl
Algorithm Hash digest
SHA256 936281520e09fe33f9c930fa3ab2ad94f70db19aefdfa9f733ddbf4eb83d7997
MD5 362a0b79096c77d7655f23f2a763e0df
BLAKE2b-256 e28ef4bcd07646d0b29736f973c70ac3d769cd047a603e43f37fe82e78a51b30

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page