Skip to content

Instantly share code, notes, and snippets.

@insolor
Created June 29, 2023 18:08
Show Gist options
  • Save insolor/c7f8b9474a11651222db4c76041f7cc9 to your computer and use it in GitHub Desktop.
Save insolor/c7f8b9474a11651222db4c76041f7cc9 to your computer and use it in GitHub Desktop.
Using trogon with typer
"""
A basic example on how to use trogon (https://github.com/Textualize/trogon) with typer (https://github.com/tiangolo/typer)
Running:
> python trogon_typer_example.py tui
"""
import click
from trogon import tui
import typer
@tui()
@click.group()
def cli():
pass
app = typer.Typer()
@app.command()
def hello(name: str, count: int):
for x in range(count):
click.echo(f"Hello {name}!")
# https://typer.tiangolo.com/tutorial/using-click/#including-a-typer-app-in-a-click-app
typer_click_object = typer.main.get_command(app)
cli.add_command(typer_click_object, "hello")
if __name__ == '__main__':
cli()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment