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
6 changes: 6 additions & 0 deletions click_repl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ def get_completions(self, document, complete_event=None):
choices = []
for param in ctx.command.params:
if isinstance(param, click.Option):
if getattr(param, "hidden", False):
continue

for options in (param.opts, param.secondary_opts):
for o in options:
choices.append(
Expand All @@ -144,6 +147,9 @@ def get_completions(self, document, complete_event=None):
if isinstance(ctx.command, click.MultiCommand):
for name in ctx.command.list_commands(ctx):
command = ctx.command.get_command(ctx, name)
if getattr(command, "hidden", False):
continue

choices.append(
Completion(
text_type(name),
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ testing =
; click_repl = py.typed

[flake8]
ignore = E203, E266, W503, E402, E731
ignore = E203, E266, W503, E402, E731, C901
max-line-length = 90
max-complexity = 18
select = B,C,E,F,W,T4,B9
31 changes: 27 additions & 4 deletions tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
from prompt_toolkit.document import Document


def test_completion():
@click.group()
def root_command():
pass
@click.group()
def root_command():
pass


def test_completion():
@root_command.group()
def first_level_command():
pass
Expand All @@ -26,3 +27,25 @@ def second_level_command_two():
assert set(x.text for x in completions) == set(
["second-level-command-one", "second-level-command-two"]
)


def test_hidden_command():
@root_command.command(hidden=True)
@click.option("--handler", "-h")
def hidden_cmd(handler):
pass

c = ClickCompleter(root_command)
completions = list(c.get_completions(Document("hidden")))
assert set(x.text for x in completions) == set()


def test_hidden_option():
@root_command.command()
@click.option("--handler", "-h", hidden=True)
def hidden_cmd(handler):
pass

c = ClickCompleter(root_command)
completions = list(c.get_completions(Document("hidden-cmd ")))
assert set(x.text for x in completions) == set()