Skip to content

Commit

Permalink
Add completion of Dialects.
Browse files Browse the repository at this point in the history
We here apparently hit a click regression, which I've filed as
pallets/click#2703.
  • Loading branch information
Julian committed Apr 4, 2024
1 parent 37e4d48 commit 545bcef
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions bowtie/_cli.py
Expand Up @@ -706,6 +706,36 @@ def convert(

self.fail(f"{value!r} is not a known dialect URI or short name.")

def shell_complete(
self,
ctx: click.Context,
param: click.Parameter,
incomplete: str,
) -> list[CompletionItem]:
if incomplete: # the user typed something, so filter over everything
suggestions = [
(field, dialect)
for dialect in Dialect.known()
for field in [
str(dialect.uri),
dialect.short_name,
*dialect.aliases,
]
]
suggestions = [(str(u), d) for u, d in Dialect.by_uri().items()]
else: # the user didn't type anything, only suggest short names
suggestions = Dialect.by_short_name().items()

return [
# FIXME: pallets/click#2703
CompletionItem(
value=value.replace(":", "\\:"),
help=f"the {dialect.pretty_name} dialect",
)
for value, dialect in suggestions
if value.startswith(incomplete.lower())
]


CaseTransform = Callable[[Iterable[TestCase]], Iterable[TestCase]]

Expand Down

0 comments on commit 545bcef

Please sign in to comment.