Coverage for docs_src/commands/help/tutorial001_an.py: 100%
19 statements
« prev ^ index » next coverage.py v7.6.1, created at 2025-12-19 20:29 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2025-12-19 20:29 +0000
1import typer 1abcdefghi
2from typing_extensions import Annotated 1abcdefghi
4app = typer.Typer(help="Awesome CLI user manager.") 1abcdefghi
7@app.command() 1abcdefghi
8def create(username: str): 1abcdefghi
9 """
10 Create a new user with USERNAME.
11 """
12 print(f"Creating user: {username}") 1abcdefghi
15@app.command() 1abcdefghi
16def delete( 1abcdefghi
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: 1abcdefghi
32 print(f"Deleting user: {username}") 1abcdefghi
33 else:
34 print("Operation cancelled") 1abcdefghi
37@app.command() 1abcdefghi
38def delete_all( 1abcdefghi
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: 1abcdefghi
53 print("Deleting all users") 1abcdefghi
54 else:
55 print("Operation cancelled") 1abcdefghi
58@app.command() 1abcdefghi
59def init(): 1abcdefghi
60 """
61 Initialize the users database.
62 """
63 print("Initializing user database") 1abcdefghi
66if __name__ == "__main__": 1abcdefghi
67 app() 1abcdefghi