diff --git a/sphinx_click/ext.py b/sphinx_click/ext.py index f398aad..c501872 100644 --- a/sphinx_click/ext.py +++ b/sphinx_click/ext.py @@ -533,12 +533,16 @@ def _generate_nodes( ) ) else: - commands = _filter_commands(ctx, commands) - for command in commands: + command_objs = _filter_commands(ctx, commands) + for command in command_objs: parent = ctx if not semantic_group else ctx.parent section.extend( self._generate_nodes( - command.name, command, parent=parent, nested=nested + command.name, + command, + parent=parent, + nested=nested, + commands=commands, ) ) diff --git a/tests/roots/nested-full/greet.py b/tests/roots/nested-full/greet.py index 8981828..c6a481a 100644 --- a/tests/roots/nested-full/greet.py +++ b/tests/roots/nested-full/greet.py @@ -16,7 +16,31 @@ def hello(user): click.echo('Hello %s' % user) -@greet.command() +@greet.group() def world(): """Greet the world.""" click.echo('Hello world!') + + +@world.command() +def peace(): + """Greet the world peace.""" + click.echo('Hello world peace!') + + +@world.command() +def traveler(): + """Greet a globetrotter.""" + click.echo('Hello world traveler!') + + +@world.group() +def wide(): + """Greet all world wide things.""" + click.echo('Hello world wide ...!') + + +@wide.command() +def web(): + """Greet the internet.""" + click.echo('Hello world wide web!') diff --git a/tests/roots/nested-full/index.rst b/tests/roots/nested-full/index.rst index ca32dd3..1e56735 100644 --- a/tests/roots/nested-full/index.rst +++ b/tests/roots/nested-full/index.rst @@ -4,3 +4,4 @@ Nested (full) .. click:: greet:greet :prog: greet :nested: full + :commands: hello, world, wide, web, peace diff --git a/tests/test_extension.py b/tests/test_extension.py index 4dfd12d..b1cb870 100644 --- a/tests/test_extension.py +++ b/tests/test_extension.py @@ -1,4 +1,5 @@ import pickle +import sys from docutils import nodes from sphinx import addnodes as sphinx_nodes @@ -91,6 +92,10 @@ def test_commands(make_app, rootdir): def test_nested_full(make_app, rootdir): + # Make sure this sphinx-click reloads the module from this rootdir. + if "greet" in sys.modules: + del sys.modules["greet"] + srcdir = rootdir / 'nested-full' app = make_app('xml', srcdir=srcdir) app.build() @@ -144,3 +149,30 @@ def test_nested_full(make_app, rootdir): assert isinstance(subsection_b[1], nodes.paragraph) assert subsection_b[1].astext() == 'Greet the world.' assert isinstance(subsection_b[2], nodes.literal_block) + + subsection_b_a = subsection_b[3] + assert isinstance(subsection_b_a, nodes.section) + + assert isinstance(subsection_b_a[0], nodes.title) + assert subsection_b_a[0].astext() == 'wide' + assert isinstance(subsection_b_a[1], nodes.paragraph) + assert subsection_b_a[1].astext() == 'Greet all world wide things.' + assert isinstance(subsection_b_a[2], nodes.literal_block) + + subsection_b_a_a = subsection_b_a[3] + assert isinstance(subsection_b_a_a, nodes.section) + + assert isinstance(subsection_b_a_a[0], nodes.title) + assert subsection_b_a_a[0].astext() == 'web' + assert isinstance(subsection_b_a_a[1], nodes.paragraph) + assert subsection_b_a_a[1].astext() == 'Greet the internet.' + assert isinstance(subsection_b_a_a[2], nodes.literal_block) + + subsection_b_b = subsection_b[4] + assert isinstance(subsection_b_b, nodes.section) + + assert isinstance(subsection_b_b[0], nodes.title) + assert subsection_b_b[0].astext() == 'peace' + assert isinstance(subsection_b_b[1], nodes.paragraph) + assert subsection_b_b[1].astext() == 'Greet the world peace.' + assert isinstance(subsection_b_b[2], nodes.literal_block)