How to use the typer.Abort function in typer

To help you get started, we’ve selected a few typer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tiangolo / typer / docs_src / parameter_types / path / tutorial001.py View on Github external
def main(config: Path = typer.Option(None)):
    if config is None:
        typer.echo("No config file")
        raise typer.Abort()
    if config.is_file():
        text = config.read_text()
        typer.echo(f"Config file contents: {text}")
    elif config.is_dir():
        typer.echo("Config is a directory, will use all its config files")
    elif not config.exists():
        typer.echo("The config doesn't exist")
github tiangolo / typer / docs_src / terminating / tutorial003.py View on Github external
def main(username: str):
    if username == "root":
        typer.echo("The root user is reserved")
        raise typer.Abort()
    typer.echo(f"New user created: {username}")
github tiangolo / typer / docs_src / multiple_values / multiple_options / tutorial001.py View on Github external
def main(user: List[str] = typer.Option(None)):
    if not user:
        typer.echo("No provided users")
        raise typer.Abort()
    for u in user:
        typer.echo(f"Processing user: {u}")
github tiangolo / typer / docs_src / multiple_values / options_with_multiple_values / tutorial001.py View on Github external
def main(user: Tuple[str, int, bool] = typer.Option((None, None, None))):
    username, coins, is_wizard = user
    if not username:
        typer.echo("No user provided")
        raise typer.Abort()
    typer.echo(f"The username {username} has {coins} coins")
    if is_wizard:
        typer.echo("And this user is a wizard!")
github tiangolo / typer / docs_src / prompt / tutorial002.py View on Github external
def main():
    delete = typer.confirm("Are you sure you want to delete it?")
    if not delete:
        typer.echo("Not deleting")
        raise typer.Abort()
    typer.echo("Deleting it!")