Skip to content

Commit

Permalink
Add local file completer
Browse files Browse the repository at this point in the history
  • Loading branch information
igrek51 committed Jun 21, 2020
1 parent 3e2df1c commit 9039c1b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cliglue/autocomplete/completers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import os


def file_completer():
files = [f for f in os.listdir('.')]
return sorted(files)
25 changes: 25 additions & 0 deletions tests/autocomplete/test_autocomplete.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from cliglue import *
from cliglue.autocomplete.completers import file_completer
from tests.asserts import MockIO


Expand Down Expand Up @@ -223,3 +224,27 @@ def test_completing_word_in_the_middle():
subcommand('run'),
).run()
assert mockio.stripped() == 'run'


def test_complete_with_completer_function():
def complete():
return ['42', '47', '53']

with MockIO('--autocomplete', '"app 4"') as mockio:
CliBuilder(reraise_error=True).has(
arguments('a', choices=complete),
).run()
assert mockio.stripped() == '42\n47'


def test_file_completer():
with MockIO('--autocomplete', '"app "') as mockio:
CliBuilder(reraise_error=True).has(
arguments('f', choices=file_completer),
).run()
proposals = mockio.stripped().splitlines()
assert '.gitignore' in proposals
assert 'tests' in proposals
assert 'tests/builder' not in proposals
assert '.' not in proposals
assert '..' not in proposals

0 comments on commit 9039c1b

Please sign in to comment.