blob: dc198f5fac5adfdd363fc1346dd05eb949c66bbc (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
"""CLI options validators."""
from pathlib import Path
def file_exists(val: str) -> Path:
"""Ensure the file path specified actually exists."""
_file = Path(val)
if _file.exists() and _file.is_file():
return _file
raise FileNotFoundError(f"Could not find the file '{_file}'.")
def directory_exists(val: str) -> Path:
"""Check that directory path specified actually exists."""
_dir = Path(val).absolute()
if _dir.is_dir() and _dir.exists():
return _dir
raise FileNotFoundError(f"The path '{_dir}' MUST exist and be a directory.")
|