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

15 statements  

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

1from pathlib import Path 1abcdefgh

2from typing import Optional 1abcdefgh

3 

4import typer 1abcdefgh

5from typing_extensions import Annotated 1abcdefgh

6 

7 

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

9 if config is None: 1abcdefgh

10 print("No config file") 1abcdefgh

11 raise typer.Abort() 1abcdefgh

12 if config.is_file(): 1abcdefgh

13 text = config.read_text() 1abcdefgh

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

15 elif config.is_dir(): 1abcdefgh

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

17 elif not config.exists(): 1abcdefgh

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

19 

20 

21if __name__ == "__main__": 1abcdefgh

22 typer.run(main) 1abcdefgh