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

16 statements  

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

1from pathlib import Path 1abcdefgh

2from typing import Annotated, Optional 1abcdefgh

3 

4import typer 1abcdefgh

5 

6app = typer.Typer() 1abcdefgh

7 

8 

9@app.command() 1abcdefgh

10def main(config: Annotated[Optional[Path], typer.Option()] = None): 1abcdefgh

11 if config is None: 1abcdefgh

12 print("No config file") 1abcdefgh

13 raise typer.Abort() 1abcdefgh

14 if config.is_file(): 1abcdefgh

15 text = config.read_text() 1abcdefgh

16 print(f"Config file contents: {text}") 1abcdefgh

17 elif config.is_dir(): 1abcdefgh

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

19 elif not config.exists(): 1abcdefgh

20 print("The config doesn't exist") 1abcdefgh

21 

22 

23if __name__ == "__main__": 1abcdefgh

24 app() 1abcdefgh