How to use the typer.Exit 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 / terminating / tutorial001.py View on Github external
def maybe_create_user(username: str):
    if username in existing_usernames:
        typer.echo("The user already exists")
        raise typer.Exit()
    else:
        typer.echo(f"User created: {username}")
github pyannote / pyannote-database / pyannote / database / cli.py View on Github external
def info(protocol: str):
    """Print protocol detailed information"""

    p = get_protocol(protocol)

    if isinstance(p, SpeakerDiarizationProtocol):
        subsets = ["train", "development", "test"]
        skip_annotation = False
        skip_annotated = False
    elif isinstance(p, CollectionProtocol):
        subsets = ["files"]
        skip_annotation = True
        skip_annotated = True
    else:
        typer.echo("Only collections and speaker diarization protocols are supported.")
        typer.Exit(code=1)

    for subset in subsets:

        num_files = 0
        speakers = set()
        duration = 0.0
        speech = 0.0

        def iterate():
            try:
                for file in getattr(p, subset)():
                    yield file
            except (AttributeError, NotImplementedError):
                return

        for file in iterate():
github tiangolo / typer / docs_src / terminating / tutorial002.py View on Github external
def main(username: str):
    if username == "root":
        typer.echo("The root user is reserved")
        raise typer.Exit(code=1)
    typer.echo(f"New user created: {username}")
github tiangolo / typer / docs_src / options / version / tutorial002.py View on Github external
def version_callback(value: bool):
    if value:
        typer.echo(f"Awesome CLI Version: {__version__}")
        raise typer.Exit()
github tiangolo / typer / docs_src / options / version / tutorial003.py View on Github external
def version_callback(value: bool):
    if value:
        typer.echo(f"Awesome CLI Version: {__version__}")
        raise typer.Exit()