Coverage for docs_src / commands / help / tutorial001_py39.py: 100%
18 statements
« prev ^ index » next coverage.py v7.13.1, created at 2026-02-09 12:36 +0000
« prev ^ index » next coverage.py v7.13.1, created at 2026-02-09 12:36 +0000
1import typer 1abcdefgh
3app = typer.Typer(help="Awesome CLI user manager.") 1abcdefgh
6@app.command() 1abcdefgh
7def create(username: str): 1abcdefgh
8 """
9 Create a new user with USERNAME.
10 """
11 print(f"Creating user: {username}") 1abcdefgh
14@app.command() 1abcdefgh
15def delete( 1abcdefgh
16 username: str,
17 force: bool = typer.Option(
18 ...,
19 prompt="Are you sure you want to delete the user?",
20 help="Force deletion without confirmation.",
21 ),
22):
23 """
24 Delete a user with USERNAME.
26 If --force is not used, will ask for confirmation.
27 """
28 if force: 1abcdefgh
29 print(f"Deleting user: {username}") 1abcdefgh
30 else:
31 print("Operation cancelled") 1abcdefgh
34@app.command() 1abcdefgh
35def delete_all( 1abcdefgh
36 force: bool = typer.Option(
37 ...,
38 prompt="Are you sure you want to delete ALL users?",
39 help="Force deletion without confirmation.",
40 ),
41):
42 """
43 Delete ALL users in the database.
45 If --force is not used, will ask for confirmation.
46 """
47 if force: 1abcdefgh
48 print("Deleting all users") 1abcdefgh
49 else:
50 print("Operation cancelled") 1abcdefgh
53@app.command() 1abcdefgh
54def init(): 1abcdefgh
55 """
56 Initialize the users database.
57 """
58 print("Initializing user database") 1abcdefgh
61if __name__ == "__main__": 1abcdefgh
62 app() 1abcdefgh