render CLI arguments (sub-commands friendly) defined by argparse module
Project description
sphinx-argparse-cli
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) when provided, overwrites the <prog> name. |
hook | (optional) hook argparse to retrieve the parser if func uses a parser instead of returning it. |
title | (optional) when provided, overwrites the <prog> - CLI interface title added by default and when empty, will not be included |
description | (optional) when provided, overwrites the description 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} |
no_default_values | (optional) supresses generation of default entries |
For example:
.. sphinx_argparse_cli::
:module: a_project.cli
:func: build_parser
:prog: my-cli-program
If you have code that creates and uses a parser but does not return it, you can specify the :hook:
flag:
.. sphinx_argparse_cli::
:module: a_project.cli
:func: main
:hook:
: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 therun
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 therun
sub-command use:ref:`cli:tox-run---magic`
.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for sphinx_argparse_cli-1.10.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | ce4eefe05c1d5ed0535384a713f91f53dbe3579895f0bc80ff55ad82e7094574 |
|
MD5 | fac4c407c58b0947fe9b29d0095f383c |
|
BLAKE2b-256 | 9f43eb2871b1c66cecacf0bee2fb5b9de5f657b8738cc8aa318d1931f03a68ff |
Hashes for sphinx_argparse_cli-1.10.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8d5951f748cbb3ca084bc0fe40ee53c3ed4c8eaa3a2c0f10e63ff72073896114 |
|
MD5 | 3a0d6dd1058211e0220aafacb61b0d79 |
|
BLAKE2b-256 | 45f44f2aeace491904f2758e8fa8df2220e1a8a19a4e71f6bde0dedb34448f58 |