Skip to content
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ htmlcov
coverage.xml
.coverage*
.cache
venv/
8 changes: 7 additions & 1 deletion typer/_completion_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,13 @@ def get_completion_args(self) -> tuple[list[str], str]:
completion_args = os.getenv("_TYPER_COMPLETE_ARGS", "")
incomplete = os.getenv("_TYPER_COMPLETE_WORD_TO_COMPLETE", "")
cwords = click_split_arg_string(completion_args)
args = cwords[1:-1] if incomplete else cwords[1:]
# cwords[0] is the interpreter (e.g. "python"), cwords[1] is the
# prog name (e.g. "main.py") — skip both, same as bash/zsh do with
# their respective word splitting. Without this, the prog name leaks
# into args and Click can't resolve the command context, causing
# completions to silently return nothing (issue #266).

args = cwords[2:-1] if incomplete else cwords[2:]
return args, incomplete

def format_completion(self, item: click.shell_completion.CompletionItem) -> str:
Expand Down
6 changes: 3 additions & 3 deletions typer/_completion_shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ class Shells(str, Enum):
[System.Management.Automation.CompletionResult]::new(
$command, $command, 'ParameterValue', $helpString)
}
$Env:%(autocomplete_var)s = ""
$Env:_TYPER_COMPLETE_ARGS = ""
$Env:_TYPER_COMPLETE_WORD_TO_COMPLETE = ""
Remove-Item Env:%(autocomplete_var)s -ErrorAction SilentlyContinue
Remove-Item Env:_TYPER_COMPLETE_ARGS -ErrorAction SilentlyContinue
Remove-Item Env:_TYPER_COMPLETE_WORD_TO_COMPLETE -ErrorAction SilentlyContinue
}
Register-ArgumentCompleter -Native -CommandName %(prog_name)s -ScriptBlock $scriptblock
"""
Expand Down
Loading