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