Skip to content

Commit cce9329

Browse files
committed
First version
Signed-off-by: Bernát Gábor <[email protected]>
1 parent e5a5182 commit cce9329

File tree

17 files changed

+378
-14
lines changed

17 files changed

+378
-14
lines changed

.pre-commit-config.yaml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,15 @@ repos:
3030
- repo: https://github.com/tox-dev/tox-ini-fmt
3131
rev: "0.5.0"
3232
hooks:
33-
- id: tox-ini-fmt
33+
- id: tox-ini-fmt
3434
- repo: https://github.com/PyCQA/flake8
3535
rev: "3.8.4"
3636
hooks:
3737
- id: flake8
38-
additional_dependencies: ["flake8-bugbear == 20.1.4"]
38+
additional_dependencies: [
39+
"flake8-bugbear == 20.11.1",
40+
"flake8-unused-arguments == 0.0.6",
41+
"flake8-comprehensions == 3.3.1",
42+
"flake8-spellcheck == 0.23.0",
43+
"flake8-pytest-style == 1.3.0",
44+
]

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
All notable changes to this project will be documented in this file.
44

5-
## unreleased
5+
## 1.0.0 (2021-02-05)
66

77
- First version.

README.md

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,35 @@
1010
[![Code style:
1111
black](https://img.shields.io/badge/code%20style-black-000000.svg?style=flat-square)](https://github.com/psf/black)
1212

13-
Render CLI arguments (sub-commands friendly) defined by argparse module.
13+
Render CLI arguments (sub-commands friendly) defined by the argparse module.
14+
15+
Demo projects:
16+
17+
- [tox](https://tox.readthedocs.io/en/rewrite/cli_interface.html)
1418

1519
## installation
1620

17-
`pip install sphinx-argparse-cli`
21+
```bash
22+
python -m pip install sphinx-argparse-cli
23+
```
24+
25+
## enable in your `conf.py`
26+
27+
```python
28+
# just add it to your list of extensions to load within conf.py
29+
extensions = ["sphinx_argparse_cli"]
30+
```
31+
32+
## use
33+
34+
Within the reStructuredText files use the `sphinx_argparse_cli` directive that takes two arguments:
35+
36+
- the module path to where the parser is defined,
37+
- a no argument function within that module that once called returns the constructed
38+
[argparse](https://docs.python.org/3/library/argparse.html) parser
39+
40+
```rst
41+
.. sphinx_argparse_cli::
42+
:module: a_project.cli
43+
:func: build_parser
44+
```

pyproject.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ known_first_party = ["sphinx_argparse_cli"]
1313
write_to = "src/sphinx_argparse_cli/version.py"
1414
write_to_template = """
1515
\"\"\" Version information \"\"\"
16+
from __future__ import annotations
1617
17-
__version__ = "{version}"
18+
__version__: str = "{version}"
1819
"""
20+
21+
[tool.pytest.ini_options]
22+
filterwarnings = [
23+
"ignore::DeprecationWarning:docutils",
24+
]

roots/test-basic/conf.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from __future__ import annotations
2+
3+
import sys
4+
from pathlib import Path
5+
6+
sys.path.insert(0, str(Path(__file__).parent))
7+
extensions = ["sphinx_argparse_cli"]
8+
nitpicky = True

roots/test-basic/index.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.. sphinx_argparse_cli::
2+
:module: parser
3+
:func: make

roots/test-basic/parser.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from __future__ import annotations
2+
3+
from argparse import ArgumentParser
4+
5+
6+
def make() -> ArgumentParser:
7+
return ArgumentParser(prog="basic")

roots/test-complex/conf.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from __future__ import annotations
2+
3+
import sys
4+
from pathlib import Path
5+
6+
sys.path.insert(0, str(Path(__file__).parent))
7+
extensions = ["sphinx_argparse_cli"]
8+
nitpicky = True

roots/test-complex/index.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.. sphinx_argparse_cli::
2+
:module: parser
3+
:func: make

roots/test-complex/parser.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
from __future__ import annotations
2+
3+
from argparse import ArgumentParser
4+
5+
6+
def make() -> ArgumentParser:
7+
parser = ArgumentParser(description="argparse tester", prog="complex")
8+
parser.add_argument("--root", action="store_true", help="root flag")
9+
parser.add_argument("--no-help", action="store_true")
10+
11+
group = parser.add_argument_group("Exclusive", description="this is an exclusive group")
12+
exclusive = group.add_mutually_exclusive_group()
13+
exclusive.add_argument("--foo", action="store_true", help="foo")
14+
exclusive.add_argument("--bar", action="store_true", help="bar")
15+
16+
parser.add_argument_group("empty")
17+
18+
sub_parsers_a = parser.add_subparsers(title="sub-parser-a", description="sub parsers A", dest="command")
19+
sub_parsers_a.required = False
20+
sub_parsers_a.default = "first"
21+
22+
a_parser_first = sub_parsers_a.add_parser("first", aliases=["f"], help="a-first-help")
23+
a_parser_first.add_argument("--flag", dest="a_par_first_flag", action="store_true", help="a parser first flag")
24+
a_parser_first.add_argument("--root", action="store_true", help="root flag")
25+
a_parser_first.add_argument("pos_one", help="first positional argument", metavar="one")
26+
a_parser_first.add_argument("pos_two", help="second positional argument", default=1)
27+
28+
a_parser_second = sub_parsers_a.add_parser("second")
29+
a_parser_second.add_argument("--flag", dest="a_par_second_flag", action="store_true", help="a parser second flag")
30+
a_parser_second.add_argument("--root", action="store_true", help="root flag")
31+
a_parser_second.add_argument("pos_one", help="first positional argument", metavar="one")
32+
a_parser_second.add_argument("pos_two", help="second positional argument", default="green")
33+
34+
sub_parsers_a.add_parser("third") # empty sub-command
35+
return parser

0 commit comments

Comments
 (0)