Coverage for docs_src / terminating / tutorial001_py310.py: 100%

14 statements  

« prev     ^ index     » next       coverage.py v7.13.1, created at 2026-03-26 21:46 +0000

1import typer 1abcdefg

2 

3existing_usernames = ["rick", "morty"] 1abcdefg

4 

5 

6def maybe_create_user(username: str): 1abcdefg

7 if username in existing_usernames: 1abcdefg

8 print("The user already exists") 1abcdefg

9 raise typer.Exit() 1abcdefg

10 else: 

11 print(f"User created: {username}") 1abcdefg

12 

13 

14def send_new_user_notification(username: str): 1abcdefg

15 # Somehow send a notification here for the new user, maybe an email 

16 print(f"Notification sent for new user: {username}") 1abcdefg

17 

18 

19app = typer.Typer() 1abcdefg

20 

21 

22@app.command() 1abcdefg

23def main(username: str): 1abcdefg

24 maybe_create_user(username=username) 1abcdefg

25 send_new_user_notification(username=username) 1abcdefg

26 

27 

28if __name__ == "__main__": 1abcdefg

29 app() 1abcdefg