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