Open a file and yield the corresponding (decoded) stream. Exits with error code 2 if the file cannot be opened.
(path: os.PathLike)
| 50 | |
| 51 | @contextmanager |
| 52 | def stream_file(path: os.PathLike) -> Iterator[IO[str]]: |
| 53 | """ |
| 54 | Open a file and yield the corresponding (decoded) stream. |
| 55 | |
| 56 | Exits with error code 2 if the file cannot be opened. |
| 57 | """ |
| 58 | |
| 59 | try: |
| 60 | with open(path) as stream: |
| 61 | yield stream |
| 62 | except OSError as exc: |
| 63 | print(f"Error opening env file: {exc}", file=sys.stderr) |
| 64 | exit(2) |
| 65 | |
| 66 | |
| 67 | @cli.command() |