Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions roots/test-subparsers-storeaction/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from __future__ import annotations

import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).parent))
extensions = ["sphinx_argparse_cli"]
nitpicky = True
3 changes: 3 additions & 0 deletions roots/test-subparsers-storeaction/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.. sphinx_argparse_cli::
:module: parser
:func: make
17 changes: 17 additions & 0 deletions roots/test-subparsers-storeaction/parser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from __future__ import annotations

from argparse import ArgumentParser


def make() -> ArgumentParser:
parser = ArgumentParser(prog="test")

sub_parsers = parser.add_subparsers()
sub_parser = sub_parsers.add_parser("subparser")
sub_parser.add_argument("foo")

sub_sub_parsers = sub_parser.add_subparsers()
sub_sub_parser = sub_sub_parsers.add_parser("child_two")
sub_sub_parser.add_argument("--bar")

return parser
3 changes: 2 additions & 1 deletion src/sphinx_argparse_cli/_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ def _load_sub_parsers(

if parser._subparsers: # noqa: SLF001
sub_sub_parser: _SubParsersAction[ArgumentParser] = parser._subparsers._group_actions[0] # type: ignore[assignment] # noqa: SLF001
yield from self._load_sub_parsers(sub_sub_parser)
if isinstance(sub_sub_parser, _SubParsersAction):
yield from self._load_sub_parsers(sub_sub_parser)

def _iter_sub_commands(self) -> Iterator[tuple[list[str], str, ArgumentParser]]:
top_sub_parser = self.parser._subparsers # noqa: SLF001
Expand Down
7 changes: 7 additions & 0 deletions tests/test_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,13 @@ def test_subparsers(build_outcome: str) -> None:
assert '<section id="test-no_child-options">' in build_outcome


@pytest.mark.sphinx(buildername="html", testroot="subparsers-storeaction")
def test_subparsers_stoeaction(build_outcome: str) -> None:
assert '<section id="test-options">' in build_outcome
assert '<section id="test-subparser">' in build_outcome
assert '<section id="test-subparser-positional-arguments">' in build_outcome


@pytest.mark.sphinx(buildername="text", testroot="bad-module")
def test_bad_module(app: SphinxTestApp, warning: StringIO) -> None:
app.build()
Expand Down