Coverage for docs_src / options / callback / tutorial003_non_an.py: 100%

12 statements  

« prev     ^ index     » next       coverage.py v7.13.1, created at 2026-11-18 11:12 +0000

1import typer 1abcdefghij

2 

3app = typer.Typer() 1abcdefghij

4 

5 

6def name_callback(ctx: typer.Context, value: str): 1abcdefghij

7 if ctx.resilient_parsing: 1abcdefghij

8 return 1abcdefghij

9 print("Validating name") 1abcdefghij

10 if value != "Camila": 1abcdefghij

11 raise typer.BadParameter("Only Camila is allowed") 1abcdefghij

12 return value 1abcdefghij

13 

14 

15@app.command() 1abcdefghij

16def main(name: str | None = typer.Option(default=None, callback=name_callback)): 1abcdefghij

17 print(f"Hello {name}") 1abcdefghij

18 

19 

20if __name__ == "__main__": 1abcdefghij

21 app() 1abcdefghij