File: types.py

package info (click to toggle)
python-cloup 3.0.8-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 936 kB
  • sloc: python: 5,371; makefile: 120
file content (53 lines) | stat: -rw-r--r-- 1,350 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"""
Parameter types and "shortcuts" for creating commonly used types.
"""
import pathlib
from typing import Type, Any

import click


def path(
    *,
    path_type: Type[Any] = pathlib.Path,
    exists: bool = False,
    file_okay: bool = True,
    dir_okay: bool = True,
    readable: bool = True,
    writable: bool = False,
    executable: bool = False,
    resolve_path: bool = False,
    allow_dash: bool = False,
) -> click.Path:
    """Shortcut for :class:`click.Path` with ``path_type=pathlib.Path``."""
    return click.Path(**locals())


def dir_path(
    *,
    path_type: Type[Any] = pathlib.Path,
    exists: bool = False,
    readable: bool = True,
    writable: bool = False,
    executable: bool = False,
    resolve_path: bool = False,
    allow_dash: bool = False,
) -> click.Path:
    """Shortcut for :class:`click.Path` with
    ``file_okay=False, path_type=pathlib.Path``."""
    return click.Path(**locals(), file_okay=False)


def file_path(
    *,
    path_type: Type[Any] = pathlib.Path,
    exists: bool = False,
    readable: bool = True,
    writable: bool = False,
    executable: bool = False,
    resolve_path: bool = False,
    allow_dash: bool = False,
) -> click.Path:
    """Shortcut for :class:`click.Path` with
    ``dir_okay=False, path_type=pathlib.Path``."""
    return click.Path(**locals(), dir_okay=False)