Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter nested commands #133

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
10 changes: 7 additions & 3 deletions sphinx_click/ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
)

Expand Down
26 changes: 25 additions & 1 deletion tests/roots/nested-full/greet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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!')
1 change: 1 addition & 0 deletions tests/roots/nested-full/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ Nested (full)
.. click:: greet:greet
:prog: greet
:nested: full
:commands: hello, world, wide, web, peace
32 changes: 32 additions & 0 deletions tests/test_extension.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pickle
import sys

from docutils import nodes
from sphinx import addnodes as sphinx_nodes
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Loading