First Check
Commit to Help
Example Code
import sys
import typer
cli = typer.Typer()
def main() -> None:
if not sys.argv[1:]:
run_gui()
return
cli()
if __name__ == "__main__":
main()
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 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:
#compdef myapp
_myapp_completion() {
eval $(env _TYPER_COMPLETE_ARGS="${words[1,$CURRENT]}" _MYAPP_COMPLETE=complete_zsh myapp)
}
compdef _myapp_completion myapp
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
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 justmyappcommand, 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-completionso 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-completionargv 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