Coverage for docs_src / parameter_types / path / tutorial001_an_py310.py: 100%
16 statements
« prev ^ index » next coverage.py v7.13.1, created at 2026-02-09 12:36 +0000
« prev ^ index » next coverage.py v7.13.1, created at 2026-02-09 12:36 +0000
1from pathlib import Path 1abcdefg
2from typing import Annotated 1abcdefg
4import typer 1abcdefg
6app = typer.Typer() 1abcdefg
9@app.command() 1abcdefg
10def main(config: Annotated[Path | None, typer.Option()] = None): 1abcdefg
11 if config is None: 1abcdefg
12 print("No config file") 1abcdefg
13 raise typer.Abort() 1abcdefg
14 if config.is_file(): 1abcdefg
15 text = config.read_text() 1abcdefg
16 print(f"Config file contents: {text}") 1abcdefg
17 elif config.is_dir(): 1abcdefg
18 print("Config is a directory, will use all its config files") 1abcdefg
19 elif not config.exists(): 1abcdefg
20 print("The config doesn't exist") 1abcdefg
23if __name__ == "__main__": 1abcdefg
24 app() 1abcdefg