| 1 |
""" |
| 2 |
Parameter types and "shortcuts" for creating commonly used types. |
| 3 |
""" |
| 4 |
import pathlib |
| 5 |
from typing import Type, Any |
| 6 |
|
| 7 |
import click |
| 8 |
|
| 9 |
|
| 10 |
def path( |
| 11 |
*, |
| 12 |
path_type: Type[Any] = pathlib.Path, |
| 13 |
exists: bool = False, |
| 14 |
file_okay: bool = True, |
| 15 |
dir_okay: bool = True, |
| 16 |
readable: bool = True, |
| 17 |
writable: bool = False, |
| 18 |
executable: bool = False, |
| 19 |
resolve_path: bool = False, |
| 20 |
allow_dash: bool = False, |
| 21 |
) -> click.Path: |
| 22 |
"""Shortcut for :class:`click.Path` with ``path_type=pathlib.Path``.""" |
| 23 |
return click.Path(**locals()) |
| 24 |
|
| 25 |
|
| 26 |
def dir_path( |
| 27 |
*, |
| 28 |
path_type: Type[Any] = pathlib.Path, |
| 29 |
exists: bool = False, |
| 30 |
readable: bool = True, |
| 31 |
writable: bool = False, |
| 32 |
executable: bool = False, |
| 33 |
resolve_path: bool = False, |
| 34 |
allow_dash: bool = False, |
| 35 |
) -> click.Path: |
| 36 |
"""Shortcut for :class:`click.Path` with |
| 37 |
``file_okay=False, path_type=pathlib.Path``.""" |
| 38 |
return click.Path(**locals(), file_okay=False) |
| 39 |
|
| 40 |
|
| 41 |
def file_path( |
| 42 |
*, |
| 43 |
path_type: Type[Any] = pathlib.Path, |
| 44 |
exists: bool = False, |
| 45 |
readable: bool = True, |
| 46 |
writable: bool = False, |
| 47 |
executable: bool = False, |
| 48 |
resolve_path: bool = False, |
| 49 |
allow_dash: bool = False, |
| 50 |
) -> click.Path: |
| 51 |
"""Shortcut for :class:`click.Path` with |
| 52 |
``dir_okay=False, path_type=pathlib.Path``.""" |
| 53 |
return click.Path(**locals(), dir_okay=False) |