Coverage for docs_src/commands/options/tutorial001.py: 100%

18 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2024-09-09 18:26 +0000

1import typer 1habcdefg

2 

3app = typer.Typer() 1habcdefg

4 

5 

6@app.command() 1habcdefg

7def create(username: str): 1habcdefg

8 print(f"Creating user: {username}") 1habcdefg

9 

10 

11@app.command() 1habcdefg

12def delete( 1abcdefg

13 username: str, 

14 force: bool = typer.Option(..., prompt="Are you sure you want to delete the user?"), 

15): 

16 if force: 1habcdefg

17 print(f"Deleting user: {username}") 1habcdefg

18 else: 

19 print("Operation cancelled") 1habcdefg

20 

21 

22@app.command() 1habcdefg

23def delete_all( 1abcdefg

24 force: bool = typer.Option( 

25 ..., prompt="Are you sure you want to delete ALL users?" 

26 ), 

27): 

28 if force: 1habcdefg

29 print("Deleting all users") 1habcdefg

30 else: 

31 print("Operation cancelled") 1habcdefg

32 

33 

34@app.command() 1habcdefg

35def init(): 1abcdefg

36 print("Initializing user database") 1habcdefg

37 

38 

39if __name__ == "__main__": 1habcdefg

40 app() 1habcdefg