Created
June 29, 2023 18:08
-
-
Save insolor/c7f8b9474a11651222db4c76041f7cc9 to your computer and use it in GitHub Desktop.
Using trogon with typer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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