|
6 | 6 |
|
7 | 7 | from colorama import Fore |
8 | 8 |
|
9 | | -from .. import config, log |
| 9 | +from .. import log |
10 | 10 | from .constants import VALID_CONFIG_DIR_FILE_EXTENSIONS |
11 | 11 |
|
12 | 12 | logger = logging.getLogger(__name__) |
@@ -63,82 +63,6 @@ def get_config_dir() -> str: |
63 | 63 | return path |
64 | 64 |
|
65 | 65 |
|
66 | | -def _validate_choices(options: t.List[str]) -> t.Callable: |
67 | | - """ |
68 | | - Callback wrapper for validating click.prompt input. |
69 | | -
|
70 | | - Parameters |
71 | | - ---------- |
72 | | - options : list |
73 | | - List of allowed choices |
74 | | -
|
75 | | - Returns |
76 | | - ------- |
77 | | - :func:`callable` |
78 | | - callback function for value_proc in :func:`click.prompt`. |
79 | | -
|
80 | | - Raises |
81 | | - ------ |
82 | | - :class:`click.BadParameter` |
83 | | - """ |
84 | | - |
85 | | - def func(value): |
86 | | - if value not in options: |
87 | | - raise ValueError("Possible choices are: {}.".format(", ".join(options))) |
88 | | - return value |
89 | | - |
90 | | - return func |
91 | | - |
92 | | - |
93 | | -class ConfigPath: |
94 | | - def __init__( |
95 | | - self, config_dir: t.Optional[t.Union[t.Callable, str]] = None, *args, **kwargs |
96 | | - ) -> None: |
97 | | - super().__init__(*args, **kwargs) |
98 | | - self.config_dir = config_dir |
99 | | - |
100 | | - def convert( |
101 | | - self, value: str, param: t.Any, ctx: t.Any |
102 | | - ) -> t.Optional[t.Union[str, pathlib.Path]]: |
103 | | - config_dir = self.config_dir() if callable(self.config_dir) else self.config_dir |
104 | | - |
105 | | - return scan_config(value, config_dir=config_dir) |
106 | | - |
107 | | - |
108 | | -def scan_config_argument(ctx, param, value, config_dir=None): |
109 | | - """Validate / translate config name/path values for click config arg. |
110 | | -
|
111 | | - Wrapper on top of :func:`cli.scan_config`.""" |
112 | | - if callable(config_dir): |
113 | | - config_dir = config_dir() |
114 | | - |
115 | | - if not config: |
116 | | - tmuxp_echo("Enter at least one CONFIG") |
117 | | - tmuxp_echo(ctx.get_help()) |
118 | | - ctx.exit() |
119 | | - |
120 | | - if isinstance(value, str): |
121 | | - value = scan_config(value, config_dir=config_dir) |
122 | | - |
123 | | - elif isinstance(value, tuple): |
124 | | - value = tuple(scan_config(v, config_dir=config_dir) for v in value) |
125 | | - |
126 | | - return value |
127 | | - |
128 | | - |
129 | | -def get_abs_path(config: str) -> str: |
130 | | - path = os.path |
131 | | - join, isabs = path.join, path.isabs |
132 | | - dirname, normpath = path.dirname, path.normpath |
133 | | - cwd = os.getcwd() |
134 | | - |
135 | | - config = os.path.expanduser(config) |
136 | | - if not isabs(config) or len(dirname(config)) > 1: |
137 | | - config = normpath(join(cwd, config)) |
138 | | - |
139 | | - return config |
140 | | - |
141 | | - |
142 | 66 | def scan_config( |
143 | 67 | config: t.Union[pathlib.Path, str], |
144 | 68 | config_dir: t.Optional[t.Union[pathlib.Path, str]] = None, |
|
0 commit comments