You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Let's say I have an application called "myapp".
This application runs in two modes - TUI/GUI and CLI. How I want it to be run is:
myapp -> run the TUI/GUI mode
myapp -h (or any other argument/option given) -> run the CLI mode via Typer
And it works fine as I have attached in the sample code, but...
There is a problem when installing auto-completion via myapp --install-completion. Since it installs #compdef with just myapp command, when I press [TAB][TAB], it tries to run in TUI/GUI mode instead of CLI.
A simple, but not ideal workaround is to edit the complete definition and place some option there like myapp --from-completion so the full script for ZSH looks like this:
and in the main() function we don't even have to edit anything since this additional --from-completion argv doesn't make the if statement to run the GUI.
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 System
Linux
Operating System Details
ubuntu:22.04
Typer Version
0.7.0
Python Version
3.8.16
Additional Context
No response
The text was updated successfully, but these errors were encountered:
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]
First Check
Commit to Help
Example Code
Description
Let's say I have an application called "myapp".
This application runs in two modes - TUI/GUI and CLI. How I want it to be run is:
myapp
-> run the TUI/GUI modemyapp -h
(or any other argument/option given) -> run the CLI mode via TyperAnd it works fine as I have attached in the sample code, but...
There is a problem when installing auto-completion via
myapp --install-completion
. Since it installs #compdef with justmyapp
command, when I press [TAB][TAB], it tries to run in TUI/GUI mode instead of CLI.A simple, but not ideal workaround is to edit the complete definition and place some option there like
myapp --from-completion
so the full script for ZSH looks like this:and in the
main()
function we don't even have to edit anything since this additional--from-completion
argv doesn't make the if statement to run the GUI.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 System
Linux
Operating System Details
ubuntu:22.04
Typer Version
0.7.0
Python Version
3.8.16
Additional Context
No response
The text was updated successfully, but these errors were encountered: