Coverage for docs_src/commands/help/tutorial001_an.py: 100%
19 statements
« prev ^ index » next coverage.py v7.6.1, created at 2024-09-09 18:26 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2024-09-09 18:26 +0000
1import typer 1habcdefg
2from typing_extensions import Annotated 1habcdefg
4app = typer.Typer(help="Awesome CLI user manager.") 1habcdefg
7@app.command() 1habcdefg
8def create(username: str): 1habcdefg
9 """
10 Create a new user with USERNAME.
11 """
12 print(f"Creating user: {username}") 1habcdefg
15@app.command() 1habcdefg
16def delete( 1abcdefg
17 username: str,
18 force: Annotated[
19 bool,
20 typer.Option(
21 prompt="Are you sure you want to delete the user?",
22 help="Force deletion without confirmation.",
23 ),
24 ],
25):
26 """
27 Delete a user with USERNAME.
29 If --force is not used, will ask for confirmation.
30 """
31 if force: 1habcdefg
32 print(f"Deleting user: {username}") 1habcdefg
33 else:
34 print("Operation cancelled") 1habcdefg
37@app.command() 1habcdefg
38def delete_all( 1abcdefg
39 force: Annotated[
40 bool,
41 typer.Option(
42 prompt="Are you sure you want to delete ALL users?",
43 help="Force deletion without confirmation.",
44 ),
45 ],
46):
47 """
48 Delete ALL users in the database.
50 If --force is not used, will ask for confirmation.
51 """
52 if force: 1habcdefg
53 print("Deleting all users") 1habcdefg
54 else:
55 print("Operation cancelled") 1habcdefg
58@app.command() 1habcdefg
59def init(): 1abcdefg
60 """
61 Initialize the users database.
62 """
63 print("Initializing user database") 1habcdefg
66if __name__ == "__main__": 1habcdefg
67 app() 1habcdefg