How to use the typer.Option 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 / tests / test_others.py View on Github external
    def main(name: str = typer.Option(..., callback=name_callback)):
        typer.echo("Hello World")
github tiangolo / typer / docs_src / options / prompt / tutorial001.py View on Github external
def main(name: str, lastname: str = typer.Option(..., prompt=True)):
    typer.echo(f"Hello {name} {lastname}")
github tiangolo / typer / docs_src / commands / help / tutorial001.py View on Github external
def delete_all(
    force: bool = typer.Option(
        ...,
        prompt="Are you sure you want to delete ALL users?",
        help="Force deletion without confirmation.",
    )
):
    """
    Delete ALL users in the database.

    If --force is not used, will ask for confirmation.
    """
    if force:
        typer.echo("Deleting all users")
    else:
        typer.echo("Operation cancelled")
github tiangolo / typer / docs_src / options / name / tutorial003.py View on Github external
def main(user_name: str = typer.Option(..., "-n")):
    typer.echo(f"Hello {user_name}")
github tiangolo / typer / docs_src / options / autocompletion / tutorial005.py View on Github external
def main(
    name: str = typer.Option(
        "World", help="The name to say hi to.", autocompletion=complete_name
    )
):
    typer.echo(f"Hello {name}")
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 / options / version / tutorial001.py View on Github external
def main(
    name: str = typer.Option("World"),
    version: bool = typer.Option(None, "--version", callback=version_callback),
):
    typer.echo(f"Hello {name}")
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 / parameter_types / file / tutorial002.py View on Github external
def main(config: typer.FileTextWrite = typer.Option(...)):
    config.write("Some config written by the app")
    typer.echo("Config written")
github tiangolo / typer / docs_src / options / help / tutorial001.py View on Github external
def main(
    name: str,
    lastname: str = typer.Option("", help="Last name of person to greet."),
    formal: bool = typer.Option(False, help="Say hi formally."),
):
    """
    Say hi to NAME, optionally with a --lastname.

    If --formal is used, say hi very formally.
    """
    if formal:
        typer.echo(f"Good day Ms. {name} {lastname}.")
    else:
        typer.echo(f"Hello {name} {lastname}")