sphinx-argparse-cli


Namesphinx-argparse-cli JSON
Version 1.15.0 PyPI version JSON
download
home_pageNone
Summaryrender CLI arguments (sub-commands friendly) defined by argparse module
upload_time2024-04-17 18:38:36
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9
licenseNone
keywords argparse sphinx
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # sphinx-argparse-cli

[![PyPI](https://img.shields.io/pypi/v/sphinx-argparse-cli?style=flat-square)](https://pypi.org/project/sphinx-argparse-cli)
[![PyPI - Implementation](https://img.shields.io/pypi/implementation/sphinx-argparse-cli?style=flat-square)](https://pypi.org/project/sphinx-argparse-cli)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/sphinx-argparse-cli?style=flat-square)](https://pypi.org/project/sphinx-argparse-cli)
[![Downloads](https://static.pepy.tech/badge/sphinx-argparse-cli/month)](https://pepy.tech/project/sphinx-argparse-cli)
[![PyPI - License](https://img.shields.io/pypi/l/sphinx-argparse-cli?style=flat-square)](https://opensource.org/licenses/MIT)
![check](https://github.com/tox-dev/sphinx-argparse-cli/workflows/check/badge.svg?branch=main)

Render CLI arguments (sub-commands friendly) defined by the argparse module. For live demo checkout the documentation of
[tox](https://tox.wiki/en/latest/cli_interface.html),
[pypa-build](https://pypa-build.readthedocs.io/en/latest/#python-m-build) and
[mdpo](https://mondeja.github.io/mdpo/latest/cli.html).

## installation

```bash
python -m pip install sphinx-argparse-cli
```

## enable in your `conf.py`

```python
# 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                                                                                        |
| epilog            | (optional) when provided, overwrites the epilog and when empty, will not be included                                                                                        |
| usage_width            | (optional) how large should usage examples be - defaults to 100 character                                                                                                        |
| usage_first            | (optional) show usage before description                                                                                                        |
| 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) suppresses generation of `default` entries                                                                                                                             |

For example:

```rst
.. 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:

```rst
.. 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 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` ``.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "sphinx-argparse-cli",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": "Bernat Gabor <gaborjbernat@gmail.com>",
    "keywords": "argparse, sphinx",
    "author": null,
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/b0/28/0248ccd0125659314ebfc4b397c660cb405d6f0d87b251ee2d417bfab58f/sphinx_argparse_cli-1.15.0.tar.gz",
    "platform": null,
    "description": "# sphinx-argparse-cli\n\n[![PyPI](https://img.shields.io/pypi/v/sphinx-argparse-cli?style=flat-square)](https://pypi.org/project/sphinx-argparse-cli)\n[![PyPI - Implementation](https://img.shields.io/pypi/implementation/sphinx-argparse-cli?style=flat-square)](https://pypi.org/project/sphinx-argparse-cli)\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/sphinx-argparse-cli?style=flat-square)](https://pypi.org/project/sphinx-argparse-cli)\n[![Downloads](https://static.pepy.tech/badge/sphinx-argparse-cli/month)](https://pepy.tech/project/sphinx-argparse-cli)\n[![PyPI - License](https://img.shields.io/pypi/l/sphinx-argparse-cli?style=flat-square)](https://opensource.org/licenses/MIT)\n![check](https://github.com/tox-dev/sphinx-argparse-cli/workflows/check/badge.svg?branch=main)\n\nRender CLI arguments (sub-commands friendly) defined by the argparse module. For live demo checkout the documentation of\n[tox](https://tox.wiki/en/latest/cli_interface.html),\n[pypa-build](https://pypa-build.readthedocs.io/en/latest/#python-m-build) and\n[mdpo](https://mondeja.github.io/mdpo/latest/cli.html).\n\n## installation\n\n```bash\npython -m pip install sphinx-argparse-cli\n```\n\n## enable in your `conf.py`\n\n```python\n# just add it to your list of extensions to load within conf.py\nextensions = [\"sphinx_argparse_cli\"]\n```\n\n## use\n\nWithin the reStructuredText files use the `sphinx_argparse_cli` directive that takes, at least, two arguments:\n\n| Name                   | Description                                                                                                                                                                      |\n| ---------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| module                 | the module path to where the parser is defined                                                                                                                                   |\n| func                   | the name of the function that once called with no arguments constructs the parser                                                                                                |\n| prog                   | (optional) when provided, overwrites the `<prog>` name.                                                                                                                          |\n| hook                   | (optional) hook `argparse` to retrieve the parser if `func` uses a parser instead of returning it.                                                                               |\n| title                  | (optional) when provided, overwrites the `<prog> - CLI interface` title added by default and when empty, will not be included                                                    |\n| description            | (optional) when provided, overwrites the description and when empty, will not be included                                                                                        |\n| epilog            | (optional) when provided, overwrites the epilog and when empty, will not be included                                                                                        |\n| usage_width            | (optional) how large should usage examples be - defaults to 100 character                                                                                                        |\n| usage_first            | (optional) show usage before description                                                                                                        |\n| group_title_prefix     | (optional) groups subsections title prefixes, accepts the string `{prog}` as a replacement for the program name - defaults to `{prog}`                                           |\n| 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}` |\n| no_default_values      | (optional) suppresses generation of `default` entries                                                                                                                             |\n\nFor example:\n\n```rst\n.. sphinx_argparse_cli::\n  :module: a_project.cli\n  :func: build_parser\n  :prog: my-cli-program\n```\n\nIf you have code that creates and uses a parser but does not return it, you can specify the `:hook:` flag:\n\n```rst\n.. sphinx_argparse_cli::\n  :module: a_project.cli\n  :func: main\n  :hook:\n  :prog: my-cli-program\n```\n\n### Refer to generated content\n\nThe tool will register reference links to all anchors. This means that you can use the sphinx `ref` role to refer to\nboth the (sub)command title/groups and every flag/argument. The tool offers a configuration flag\n`sphinx_argparse_cli_prefix_document` (change by setting this variable in `conf.py` - by default `False`). This option\ninfluences the reference ids generated. If it's false the reference will be the anchor id (the text appearing after the\n`'#` 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\nto avoid reference label clash when the same anchors are generated in multiple documents).\n\nFor example in case of a `tox` command, and `sphinx_argparse_cli_prefix_document=False` (default):\n\n- to refer to the optional arguments group use ``:ref:`tox-optional-arguments` ``,\n- to refer to the run subcommand use ``:ref:`tox-run` ``,\n- to refer to flag `--magic` of the `run` sub-command use ``:ref:`tox-run---magic` ``.\n\nFor example in case of a `tox` command, and `sphinx_argparse_cli_prefix_document=True`, and the current document name\nbeing `cli`:\n\n- to refer to the optional arguments group use ``:ref:`cli:tox-optional-arguments` ``,\n- to refer to the run subcommand use ``:ref:`cli:tox-run` ``,\n- to refer to flag `--magic` of the `run` sub-command use ``:ref:`cli:tox-run---magic` ``.\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "render CLI arguments (sub-commands friendly) defined by argparse module",
    "version": "1.15.0",
    "project_urls": {
        "Documentation": "https://github.com/tox-dev/sphinx-argparse-cli#sphinx-argparse-cli",
        "Homepage": "https://github.com/tox-dev/sphinx-argparse-cli",
        "Source": "https://github.com/tox-dev/sphinx-argparse-cli",
        "Tracker": "https://github.com/tox-dev/sphinx-argparse-cli/issues"
    },
    "split_keywords": [
        "argparse",
        " sphinx"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3bf80cf9d29d70f9aea03a1454fc62fe1b1cef4ed0229475c5f06cdc3e06164d",
                "md5": "ea790a87a8134b0a96f4839da2043764",
                "sha256": "831ca0791fd575b4b8062afe57223b09526e2e41ac68242b014eef600c751e41"
            },
            "downloads": -1,
            "filename": "sphinx_argparse_cli-1.15.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "ea790a87a8134b0a96f4839da2043764",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 9168,
            "upload_time": "2024-04-17T18:38:35",
            "upload_time_iso_8601": "2024-04-17T18:38:35.045928Z",
            "url": "https://files.pythonhosted.org/packages/3b/f8/0cf9d29d70f9aea03a1454fc62fe1b1cef4ed0229475c5f06cdc3e06164d/sphinx_argparse_cli-1.15.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b0280248ccd0125659314ebfc4b397c660cb405d6f0d87b251ee2d417bfab58f",
                "md5": "82f280d69d5e495af61a8de1dfe7397b",
                "sha256": "726cf4679fa7bf8d80f9f96afb95fa84219cac6d2dab173102175ce380ede8ed"
            },
            "downloads": -1,
            "filename": "sphinx_argparse_cli-1.15.0.tar.gz",
            "has_sig": false,
            "md5_digest": "82f280d69d5e495af61a8de1dfe7397b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 11651,
            "upload_time": "2024-04-17T18:38:36",
            "upload_time_iso_8601": "2024-04-17T18:38:36.850410Z",
            "url": "https://files.pythonhosted.org/packages/b0/28/0248ccd0125659314ebfc4b397c660cb405d6f0d87b251ee2d417bfab58f/sphinx_argparse_cli-1.15.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-17 18:38:36",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "tox-dev",
    "github_project": "sphinx-argparse-cli#sphinx-argparse-cli",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "sphinx-argparse-cli"
}
        
Elapsed time: 0.25042s