-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_47.py
More file actions
76 lines (60 loc) · 1.56 KB
/
Copy pathexample_47.py
File metadata and controls
76 lines (60 loc) · 1.56 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import typer
from typing_extensions import Annotated
"""See https://typer.tiangolo.com/tutorial/commands/help/"""
# Command Help
# You can add help for the commands in the docstrings and CLI options
# just as before
# Also, the `typer.Typer()` application receives a parameter `help`
# that you can pass with the main help text for your CLI program
app = typer.Typer(help="Awesome CLI user manager.")
@app.command()
def create(username: str):
"""
Create a new user with USERNAME.
"""
print(f"Creating user: {username}")
@app.command()
def delete(
username: str,
force: Annotated[
bool,
typer.Option(
prompt="Are you sure you want to delete the user?",
help="Force deletion without confirmation.",
),
],
):
"""
Delete a user with USERNAME.
If --force is not used, will ask for confirmation.
"""
if force:
print(f"Deleting user: {username}")
else:
print("Operation cancelled")
@app.command()
def delete_all(
force: Annotated[
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:
print("Deleting all users")
else:
print("Operation cancelled")
@app.command()
def init():
"""
Initialize the users database.
"""
print("Initializing user database")
if __name__ == "__main__":
app()