-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_50.py
More file actions
55 lines (41 loc) · 1.51 KB
/
Copy pathexample_50.py
File metadata and controls
55 lines (41 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import typer
from typing_extensions import Annotated
"""See https://typer.tiangolo.com/tutorial/commands/help/"""
# Rich Markup
# If you have Rich installed you can configure your app to enable
# markup text with the parameter `rich_markup_mode`
# NB Rich Markup is rich's font colours and attributes
# (As opposed to Rich Markdown which relates to Markdown)
# Checkout https://rich.readthedocs.io/en/stable/markup.html
# Then you can use more formatting in the docstrings and `help`
# parameter for CLI Arguments and CLI Options
# By default `rich_markup_mode` is `None` which disables any rich
# text formatting
# Check the help text below, there are a bunch of different things going on
app = typer.Typer(rich_markup_mode="rich")
@app.command()
def create(
username: Annotated[
str, typer.Argument(help="The username to be [green]created[/green]")
],
):
"""
[bold green]Create[/bold green] a new [italic]shinny[/italic] user. :sparkles:
This requires a [underline]username[/underline].
"""
print(f"Creating user: {username}")
@app.command(help="[bold red]Delete[/bold red] a user with [italic]USERNAME[/italic].")
def delete(
username: Annotated[
str, typer.Argument(help="The username to be [red]deleted[/red]")
],
force: Annotated[
bool, typer.Option(help="Force the [bold red]deletion[/bold red] :boom:")
] = False,
):
"""
Some internal utility function to delete.
"""
print(f"Deleting user: {username}")
if __name__ == "__main__":
app()