-
First Check
Commit to Help
Example Codefrom typing import Optional, List
from typer import style, echo, Typer, Exit, Argument, Option, Context
def complete_path(ctx: Context, args: List[str], incomplete: str):
#usually when autocompleting, if you return a empty list,
#typer will allow the console to autocomplete, except that
#for arguments, a space is added no matter what you type, which ruins it
return []
def single(cfg: Path = Argument(None, exists=True, file_okay=True, dir_okay=False, readable=True, resolve_path=True,shell_complete=complete_path)):
pass
if __name__ == "__main__":
app = Typer(add_completion=True)
app.command()(single)
app() DescriptionAs the example mentions, autocomplete for paths or files depends on the text cursor not moving. Whenever you try to autocomplete a typer.Argument, except the first time (before you write anything and incomplete is empty), even if you return a empty list you get a space added to the end. If you do that (return a empty list) in a Option shell_complete function, it instead fall-backs to the cmd line path autocomplete correctly, with no space added which allows autocomplete to function. I don't get this inconsistency. Actually it might not even be adding the autocomplete to the argument, because i just printed something there and nothing happened. I added the autocomplete in a attempt to workaround this behavior, which is the default. edit: shell_complete doesn't work as a argument to ... Argument, but autocompletion=complete_path does. In that case, the program doesn't add a space at the end and it works as expected. Operating SystemLinux Operating System DetailsNo response Typer Version0.9.0 Python VersionPython 3.10.6 Additional ContextNo response |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Maybe it's on purpose that any path is considered 'complete' even paths that don't exist? If so, maybe specifying exists=True could modify that? |
Beta Was this translation helpful? Give feedback.
-
This has been fixed by #1138, and is available since Typer v0.15.3 🎉 |
Beta Was this translation helpful? Give feedback.
This has been fixed by #1138, and is available since Typer v0.15.3 🎉