"README.md" did not exist on "cc9196830c161f55dbb525d6726719e944b496bf"
Select Git revision
utils.py 591 B
"""Utils."""
import argparse
from pathlib import Path
from typing import Optional
def existing_file_path(value: str, allow_none=False) -> Optional[Path]:
if not value or value.lower() == "none":
if allow_none:
return None
else:
raise argparse.ArgumentTypeError("`none` is not allowed here.")
path = Path(value)
if path.is_dir():
raise argparse.ArgumentTypeError(f"{value} is a directory. A file is required.")
elif not path.is_file():
raise argparse.ArgumentTypeError(f"{value} does not exist.")
return path