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

🐛 Ensure that autocompletion works for Path arguments/options #1138

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
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
3 changes: 2 additions & 1 deletion typer/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
ParamMeta,
Required,
TyperInfo,
TyperPath,
)
from .utils import get_params_from_function

Expand Down Expand Up @@ -744,7 +745,7 @@ def get_click_type(
or parameter_info.path_type
or parameter_info.resolve_path
):
return click.Path(
return TyperPath(
exists=parameter_info.exists,
file_okay=parameter_info.file_okay,
dir_okay=parameter_info.dir_okay,
Expand Down
11 changes: 11 additions & 0 deletions typer/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,3 +531,14 @@ def __init__(
self.pretty_exceptions_enable = pretty_exceptions_enable
self.pretty_exceptions_show_locals = pretty_exceptions_show_locals
self.pretty_exceptions_short = pretty_exceptions_short


class TyperPath(click.Path):
# Overwrite Click's behaviour to be compatible with Typer's autocompletion system
def shell_complete(
self, ctx: click.Context, param: click.Parameter, incomplete: str
) -> List[click.shell_completion.CompletionItem]:
"""Return an empty list so that the autocompletion functionality
will work properly from the commandline.
"""
return []
Loading