Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import typer

from typer import Context, Option


app = typer.Typer(help="Operations for e-commerce.")
app_user = typer.Typer(help="Operations for user model.")
app_product = typer.Typer(help="Operations for product model.")

app.add_typer(app_user, name="user")
app.add_typer(app_product, name="product")

@app.callback(invoke_without_command=True)
def main(
ctx: Context,
version: bool = Option(
None,
"--version",
"-v",
is_flag=True,
help="Show the version and exit.",
),
) -> None:
"""Process envers for specific flags, otherwise show the help menu."""
if version:
__version__ = "0.1.0"
typer.echo(f"Version: {__version__}")
raise typer.Exit()

if ctx.invoked_subcommand is None:
typer.echo(ctx.get_help())
raise typer.Exit(0)

@app_user.command("create")
def user_create(name: str = typer.Argument(..., help="Name of the user to create.")) -> None:
"""Create a new user with the given name."""
print(f"Creating user: {name} - Done")


@app_user.command("update")
def user_update(name: str = typer.Argument(..., help="Name of the user to update.")) -> None:
"""Update user data with the given name."""
print(f"Updating user: {name} - Done")

@app_product.command("create")
def product_create(name: str = typer.Argument(..., help="Name of the product to create.")) -> None:
"""Create a new product with the given name."""
print(f"Creating product: {name} - Done")


@app_product.command("update")
def product_update(name: str = typer.Argument(..., help="Name of the product to update.")) -> None:
"""Update a product with the given name."""
print(f"Updating product: {name} - Done")


if __name__ == "__main__":
app()
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

import typer

app = typer.Typer()

@app.command()
def greet(
name: str = typer.Option(
...,
"--name",
help="The name of the person to greet."
)
) -> None:
"""Greets the user by name."""
typer.echo(f"Hello {name}!")

if __name__ == "__main__":
app()
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading