Coverage for docs_src / parameter_types / path / tutorial001_py310.py: 100%

15 statements  

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

1from pathlib import Path 1abcdefg

2 

3import typer 1abcdefg

4 

5app = typer.Typer() 1abcdefg

6 

7 

8@app.command() 1abcdefg

9def main(config: Path | None = typer.Option(None)): 1abcdefg

10 if config is None: 1abcdefg

11 print("No config file") 1abcdefg

12 raise typer.Abort() 1abcdefg

13 if config.is_file(): 1abcdefg

14 text = config.read_text() 1abcdefg

15 print(f"Config file contents: {text}") 1abcdefg

16 elif config.is_dir(): 1abcdefg

17 print("Config is a directory, will use all its config files") 1abcdefg

18 elif not config.exists(): 1abcdefg

19 print("The config doesn't exist") 1abcdefg

20 

21 

22if __name__ == "__main__": 1abcdefg

23 app() 1abcdefg