diff --git a/roots/test-subparsers-storeaction/conf.py b/roots/test-subparsers-storeaction/conf.py new file mode 100644 index 0000000..9f2a54a --- /dev/null +++ b/roots/test-subparsers-storeaction/conf.py @@ -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 diff --git a/roots/test-subparsers-storeaction/index.rst b/roots/test-subparsers-storeaction/index.rst new file mode 100644 index 0000000..708ad9c --- /dev/null +++ b/roots/test-subparsers-storeaction/index.rst @@ -0,0 +1,3 @@ +.. sphinx_argparse_cli:: + :module: parser + :func: make diff --git a/roots/test-subparsers-storeaction/parser.py b/roots/test-subparsers-storeaction/parser.py new file mode 100644 index 0000000..6219a3a --- /dev/null +++ b/roots/test-subparsers-storeaction/parser.py @@ -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 diff --git a/src/sphinx_argparse_cli/_logic.py b/src/sphinx_argparse_cli/_logic.py index 93083b8..ded07f5 100644 --- a/src/sphinx_argparse_cli/_logic.py +++ b/src/sphinx_argparse_cli/_logic.py @@ -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 diff --git a/tests/test_logic.py b/tests/test_logic.py index 0699d5e..26de84e 100644 --- a/tests/test_logic.py +++ b/tests/test_logic.py @@ -369,6 +369,13 @@ def test_subparsers(build_outcome: str) -> None: assert '
' in build_outcome +@pytest.mark.sphinx(buildername="html", testroot="subparsers-storeaction") +def test_subparsers_stoeaction(build_outcome: str) -> None: + assert '
' in build_outcome + assert '
' in build_outcome + assert '
' in build_outcome + + @pytest.mark.sphinx(buildername="text", testroot="bad-module") def test_bad_module(app: SphinxTestApp, warning: StringIO) -> None: app.build()