Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def main(name: str = typer.Option(..., callback=name_callback)):
typer.echo("Hello World")
def main(name: str, lastname: str = typer.Option(..., prompt=True)):
typer.echo(f"Hello {name} {lastname}")
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")
def main(user_name: str = typer.Option(..., "-n")):
typer.echo(f"Hello {user_name}")
def main(
name: str = typer.Option(
"World", help="The name to say hi to.", autocompletion=complete_name
)
):
typer.echo(f"Hello {name}")
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!")
def main(
name: str = typer.Option("World"),
version: bool = typer.Option(None, "--version", callback=version_callback),
):
typer.echo(f"Hello {name}")
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")
def main(config: typer.FileTextWrite = typer.Option(...)):
config.write("Some config written by the app")
typer.echo("Config written")
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}")