TAB completion is giving local directory files where command is called.
First Check
- [X] I added a very descriptive title to this issue.
- [X] I used the GitHub search to find a similar issue and didn't find it.
- [X] I searched the Typer documentation, with the integrated search.
- [X] I already searched in Google "How to X in Typer" and didn't find any information.
- [X] I already read and followed all the tutorial in the docs and didn't find an answer.
- [X] I already checked if it is not related to Typer but to Click.
Commit to Help
- [X] I commit to help with one of those options 👆
Example Code
#!/usr/bin/env python3
import typer
mgmt_ip_cfg_app = typer.Typer(help="Management Interface Configuration", no_args_is_help=True)
@mgmt_ip_cfg_app.command("Ipv4",
no_args_is_help=True)
def ipv4_cfg(
ip: str = typer.Argument(...),
gateway: str = typer.Argument(...),
prefixlen: str = typer.Argument(...)):
pass
@mgmt_ip_cfg_app.command("Ipv6",
no_args_is_help=True)
def ipv6_cfg(
ip: str = typer.Argument(...),
gateway: str = typer.Argument(...),
prefixlen: str = typer.Argument(...)):
pass
def main():
mgmt_ip_cfg_app()
if __name__ == '__main__':
main()
Description
Hi,
I am new to typer. Kindly point me to doc/issue if this issue is already resolved. I have written a small cli completion code tmp.py and executed "./tmp.py --install-completion bash".
When i tried to do tab completion , if no files are there tmp.py is repeating "./tmp.py Ipv4 tmp.py tmp.py" or if any files is there, they are getting displayed in the directory where i am calling this script. Could you please help me to resolve this. I am expecting if the last command is reached it should either display help on TAB or dont display anything so that user will enter to get help.
If there are local files, TAB after Ipv4, they are getting displayed.
[root@Linux]# ./tmp.py Ipv4
1 tmp.py
Operating System
Linux
Operating System Details
No response
Typer Version
0.7.0
Python Version
3.6.8
Additional Context
No response
Hi,
I had the same issue. I had the wrong order of zsh-completion commands in my .zshrc. Try to add this to your .zshrc:
autoload -Uz compinit
zstyle ':completion:*' menu select
fpath+=~/.zfunc
compinit
Thanks @shelper https://github.com/tiangolo/typer/issues/54#issuecomment-901209114
Same issue, not resolved yet
Thanks for the report! For the zsh shell, this should be fixed with https://github.com/tiangolo/typer/pull/237, which essentially contains the same fix as @relativityhd mentioned here.
I've tried the #237, but not resolved yet. Version: typer == 0.12.3 Here is my .zshrc about completion.
autoload -Uz compinit
zstyle ':completion:*' menu select
fpath+=~/.zfunc
compinit
When I do same thing with the document, my shell can only dispaly the file in current dictory after pressing [tab] [tab]
@Zhang-Zelong: can you remove the second line from your .zshrc (take a backup first), restart the console, and try again? The file should look like this:
autoload -Uz compinit
fpath+=~/.zfunc
compinit
Okay! That works for me, thank you.
So is it a special case or a common bug? Should we fix this snippets in this file typer/_completion_shared.py ?
It's a known bug that has already been fixed by PR https://github.com/tiangolo/typer/pull/237, but requires a final review before it will be merged into master and released with the next Typer update.
Thanks all! This was handled in https://github.com/fastapi/typer/pull/237, it will be available in Typer 0.12.4, released in the next hours. :tada: