Coverage for docs_src / commands / options / tutorial001_an_py39.py: 100%
19 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
1from typing import Annotated 1abcdefgh
3import typer 1abcdefgh
5app = typer.Typer() 1abcdefgh
8@app.command() 1abcdefgh
9def create(username: str): 1abcdefgh
10 print(f"Creating user: {username}") 1abcdefgh
13@app.command() 1abcdefgh
14def delete( 1abcdefgh
15 username: str,
16 force: Annotated[
17 bool, typer.Option(prompt="Are you sure you want to delete the user?")
18 ],
19):
20 if force: 1abcdefgh
21 print(f"Deleting user: {username}") 1abcdefgh
22 else:
23 print("Operation cancelled") 1abcdefgh
26@app.command() 1abcdefgh
27def delete_all( 1abcdefgh
28 force: Annotated[
29 bool, typer.Option(prompt="Are you sure you want to delete ALL users?")
30 ],
31):
32 if force: 1abcdefgh
33 print("Deleting all users") 1abcdefgh
34 else:
35 print("Operation cancelled") 1abcdefgh
38@app.command() 1abcdefgh
39def init(): 1abcdefgh
40 print("Initializing user database") 1abcdefgh
43if __name__ == "__main__": 1abcdefgh
44 app() 1abcdefgh