-
First Check
Commit to Help
Example Codeimport sys
import typer
cli = typer.Typer()
def main() -> None:
if not sys.argv[1:]:
run_gui()
return
cli()
if __name__ == "__main__":
main()DescriptionLet's say I have an application called "myapp".
And it works fine as I have attached in the sample code, but... A simple, but not ideal workaround is to edit the complete definition and place some option there like and in the But this workaround requires some action to do from the app user side. (manually editing the autocomplete definition script) Is there another way to perform a check if the application was just run while [TAB][TAB] occurs? Operating SystemLinux Operating System Detailsubuntu:22.04 Typer Version0.7.0 Python Version3.8.16 Additional ContextNo response |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
One way I found is to perform additional checks like: if not sys.argv[1:] and sys.stdin and sys.stdin.isatty():
run_gui()and it works since the EDIT: if not sys.argv[1:] and "_MYAPP_COMPLETE" not in os.environ:
run_gui() |
Beta Was this translation helpful? Give feedback.
One way I found is to perform additional checks like:
and it works since the
sys.stdin.isatty()is False when running from [TAB][TAB],but I haven't fully tested it yet, and there might be a better way to do this.
EDIT:
Actually, since it looks like _MYAPP_COMPLETE env var is set in every compdef (bash zsh etc.) It is a better way to check if we are in the application from [TAB][TAB]