Coverage for typer/params.py: 100%
7 statements
« prev ^ index » next coverage.py v7.6.1, created at 2024-11-13 11:07 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2024-11-13 11:07 +0000
1from typing import TYPE_CHECKING, Any, Callable, List, Optional, Type, Union, overload 1habcdefg
3import click 1habcdefg
5from .models import ArgumentInfo, OptionInfo 1habcdefg
7if TYPE_CHECKING: # pragma: no cover 1habcdefg
8 import click.shell_completion
11# Overload for Option created with custom type 'parser'
12@overload 1habcdefg
13def Option( 1abcdefg
14 # Parameter
15 default: Optional[Any] = ..., 1habcdefg
16 *param_decls: str, 1abcdefg
17 callback: Optional[Callable[..., Any]] = None, 1habcdefg
18 metavar: Optional[str] = None, 1habcdefg
19 expose_value: bool = True, 1habcdefg
20 is_eager: bool = False, 1habcdefg
21 envvar: Optional[Union[str, List[str]]] = None, 1habcdefg
22 shell_complete: Optional[ 1abcdefg
23 Callable[ 1abcdefg
24 [click.Context, click.Parameter, str], 1abcdefg
25 Union[List["click.shell_completion.CompletionItem"], List[str]], 1abcdefg
26 ]
27 ] = None, 1habcdefg
28 autocompletion: Optional[Callable[..., Any]] = None, 1habcdefg
29 default_factory: Optional[Callable[[], Any]] = None, 1habcdefg
30 # Custom type
31 parser: Optional[Callable[[str], Any]] = None, 1habcdefg
32 # Option
33 show_default: Union[bool, str] = True, 1habcdefg
34 prompt: Union[bool, str] = False, 1habcdefg
35 confirmation_prompt: bool = False, 1habcdefg
36 prompt_required: bool = True, 1habcdefg
37 hide_input: bool = False, 1habcdefg
38 # TODO: remove is_flag and flag_value in a future release
39 is_flag: Optional[bool] = None, 1habcdefg
40 flag_value: Optional[Any] = None, 1habcdefg
41 count: bool = False, 1habcdefg
42 allow_from_autoenv: bool = True, 1habcdefg
43 help: Optional[str] = None, 1habcdefg
44 hidden: bool = False, 1habcdefg
45 show_choices: bool = True, 1habcdefg
46 show_envvar: bool = True, 1habcdefg
47 # Choice
48 case_sensitive: bool = True, 1habcdefg
49 # Numbers
50 min: Optional[Union[int, float]] = None, 1habcdefg
51 max: Optional[Union[int, float]] = None, 1habcdefg
52 clamp: bool = False, 1habcdefg
53 # DateTime
54 formats: Optional[List[str]] = None, 1habcdefg
55 # File
56 mode: Optional[str] = None, 1habcdefg
57 encoding: Optional[str] = None, 1habcdefg
58 errors: Optional[str] = "strict", 1habcdefg
59 lazy: Optional[bool] = None, 1habcdefg
60 atomic: bool = False, 1habcdefg
61 # Path
62 exists: bool = False, 1habcdefg
63 file_okay: bool = True, 1habcdefg
64 dir_okay: bool = True, 1habcdefg
65 writable: bool = False, 1habcdefg
66 readable: bool = True, 1habcdefg
67 resolve_path: bool = False, 1habcdefg
68 allow_dash: bool = False, 1habcdefg
69 path_type: Union[None, Type[str], Type[bytes]] = None, 1habcdefg
70 # Rich settings
71 rich_help_panel: Union[str, None] = None, 1habcdefg
72) -> Any: ... 1habcdefg
75# Overload for Option created with custom type 'click_type'
76@overload 1habcdefg
77def Option( 1abcdefg
78 # Parameter
79 default: Optional[Any] = ..., 1habcdefg
80 *param_decls: str, 1abcdefg
81 callback: Optional[Callable[..., Any]] = None, 1habcdefg
82 metavar: Optional[str] = None, 1habcdefg
83 expose_value: bool = True, 1habcdefg
84 is_eager: bool = False, 1habcdefg
85 envvar: Optional[Union[str, List[str]]] = None, 1habcdefg
86 shell_complete: Optional[ 1abcdefg
87 Callable[ 1abcdefg
88 [click.Context, click.Parameter, str], 1abcdefg
89 Union[List["click.shell_completion.CompletionItem"], List[str]], 1abcdefg
90 ]
91 ] = None, 1habcdefg
92 autocompletion: Optional[Callable[..., Any]] = None, 1habcdefg
93 default_factory: Optional[Callable[[], Any]] = None, 1habcdefg
94 # Custom type
95 click_type: Optional[click.ParamType] = None, 1habcdefg
96 # Option
97 show_default: Union[bool, str] = True, 1habcdefg
98 prompt: Union[bool, str] = False, 1habcdefg
99 confirmation_prompt: bool = False, 1habcdefg
100 prompt_required: bool = True, 1habcdefg
101 hide_input: bool = False, 1habcdefg
102 # TODO: remove is_flag and flag_value in a future release
103 is_flag: Optional[bool] = None, 1habcdefg
104 flag_value: Optional[Any] = None, 1habcdefg
105 count: bool = False, 1habcdefg
106 allow_from_autoenv: bool = True, 1habcdefg
107 help: Optional[str] = None, 1habcdefg
108 hidden: bool = False, 1habcdefg
109 show_choices: bool = True, 1habcdefg
110 show_envvar: bool = True, 1habcdefg
111 # Choice
112 case_sensitive: bool = True, 1habcdefg
113 # Numbers
114 min: Optional[Union[int, float]] = None, 1habcdefg
115 max: Optional[Union[int, float]] = None, 1habcdefg
116 clamp: bool = False, 1habcdefg
117 # DateTime
118 formats: Optional[List[str]] = None, 1habcdefg
119 # File
120 mode: Optional[str] = None, 1habcdefg
121 encoding: Optional[str] = None, 1habcdefg
122 errors: Optional[str] = "strict", 1habcdefg
123 lazy: Optional[bool] = None, 1habcdefg
124 atomic: bool = False, 1habcdefg
125 # Path
126 exists: bool = False, 1habcdefg
127 file_okay: bool = True, 1habcdefg
128 dir_okay: bool = True, 1habcdefg
129 writable: bool = False, 1habcdefg
130 readable: bool = True, 1habcdefg
131 resolve_path: bool = False, 1habcdefg
132 allow_dash: bool = False, 1habcdefg
133 path_type: Union[None, Type[str], Type[bytes]] = None, 1habcdefg
134 # Rich settings
135 rich_help_panel: Union[str, None] = None, 1habcdefg
136) -> Any: ... 1habcdefg
139def Option( 1abcdefg
140 # Parameter
141 default: Optional[Any] = ...,
142 *param_decls: str,
143 callback: Optional[Callable[..., Any]] = None,
144 metavar: Optional[str] = None,
145 expose_value: bool = True,
146 is_eager: bool = False,
147 envvar: Optional[Union[str, List[str]]] = None,
148 shell_complete: Optional[
149 Callable[
150 [click.Context, click.Parameter, str],
151 Union[List["click.shell_completion.CompletionItem"], List[str]],
152 ]
153 ] = None,
154 autocompletion: Optional[Callable[..., Any]] = None,
155 default_factory: Optional[Callable[[], Any]] = None,
156 # Custom type
157 parser: Optional[Callable[[str], Any]] = None,
158 click_type: Optional[click.ParamType] = None,
159 # Option
160 show_default: Union[bool, str] = True,
161 prompt: Union[bool, str] = False,
162 confirmation_prompt: bool = False,
163 prompt_required: bool = True,
164 hide_input: bool = False,
165 # TODO: remove is_flag and flag_value in a future release
166 is_flag: Optional[bool] = None,
167 flag_value: Optional[Any] = None,
168 count: bool = False,
169 allow_from_autoenv: bool = True,
170 help: Optional[str] = None,
171 hidden: bool = False,
172 show_choices: bool = True,
173 show_envvar: bool = True,
174 # Choice
175 case_sensitive: bool = True,
176 # Numbers
177 min: Optional[Union[int, float]] = None,
178 max: Optional[Union[int, float]] = None,
179 clamp: bool = False,
180 # DateTime
181 formats: Optional[List[str]] = None,
182 # File
183 mode: Optional[str] = None,
184 encoding: Optional[str] = None,
185 errors: Optional[str] = "strict",
186 lazy: Optional[bool] = None,
187 atomic: bool = False,
188 # Path
189 exists: bool = False,
190 file_okay: bool = True,
191 dir_okay: bool = True,
192 writable: bool = False,
193 readable: bool = True,
194 resolve_path: bool = False,
195 allow_dash: bool = False,
196 path_type: Union[None, Type[str], Type[bytes]] = None,
197 # Rich settings
198 rich_help_panel: Union[str, None] = None,
199) -> Any:
200 return OptionInfo( 1habcdefg
201 # Parameter
202 default=default,
203 param_decls=param_decls,
204 callback=callback,
205 metavar=metavar,
206 expose_value=expose_value,
207 is_eager=is_eager,
208 envvar=envvar,
209 shell_complete=shell_complete,
210 autocompletion=autocompletion,
211 default_factory=default_factory,
212 # Custom type
213 parser=parser,
214 click_type=click_type,
215 # Option
216 show_default=show_default,
217 prompt=prompt,
218 confirmation_prompt=confirmation_prompt,
219 prompt_required=prompt_required,
220 hide_input=hide_input,
221 is_flag=is_flag,
222 flag_value=flag_value,
223 count=count,
224 allow_from_autoenv=allow_from_autoenv,
225 help=help,
226 hidden=hidden,
227 show_choices=show_choices,
228 show_envvar=show_envvar,
229 # Choice
230 case_sensitive=case_sensitive,
231 # Numbers
232 min=min,
233 max=max,
234 clamp=clamp,
235 # DateTime
236 formats=formats,
237 # File
238 mode=mode,
239 encoding=encoding,
240 errors=errors,
241 lazy=lazy,
242 atomic=atomic,
243 # Path
244 exists=exists,
245 file_okay=file_okay,
246 dir_okay=dir_okay,
247 writable=writable,
248 readable=readable,
249 resolve_path=resolve_path,
250 allow_dash=allow_dash,
251 path_type=path_type,
252 # Rich settings
253 rich_help_panel=rich_help_panel,
254 )
257# Overload for Argument created with custom type 'parser'
258@overload 1habcdefg
259def Argument( 1abcdefg
260 # Parameter
261 default: Optional[Any] = ..., 1habcdefg
262 *,
263 callback: Optional[Callable[..., Any]] = None, 1habcdefg
264 metavar: Optional[str] = None, 1habcdefg
265 expose_value: bool = True, 1habcdefg
266 is_eager: bool = False, 1habcdefg
267 envvar: Optional[Union[str, List[str]]] = None, 1habcdefg
268 shell_complete: Optional[ 1abcdefg
269 Callable[ 1abcdefg
270 [click.Context, click.Parameter, str], 1abcdefg
271 Union[List["click.shell_completion.CompletionItem"], List[str]], 1abcdefg
272 ]
273 ] = None, 1habcdefg
274 autocompletion: Optional[Callable[..., Any]] = None, 1habcdefg
275 default_factory: Optional[Callable[[], Any]] = None, 1habcdefg
276 # Custom type
277 parser: Optional[Callable[[str], Any]] = None, 1habcdefg
278 # TyperArgument
279 show_default: Union[bool, str] = True, 1habcdefg
280 show_choices: bool = True, 1habcdefg
281 show_envvar: bool = True, 1habcdefg
282 help: Optional[str] = None, 1habcdefg
283 hidden: bool = False, 1habcdefg
284 # Choice
285 case_sensitive: bool = True, 1habcdefg
286 # Numbers
287 min: Optional[Union[int, float]] = None, 1habcdefg
288 max: Optional[Union[int, float]] = None, 1habcdefg
289 clamp: bool = False, 1habcdefg
290 # DateTime
291 formats: Optional[List[str]] = None, 1habcdefg
292 # File
293 mode: Optional[str] = None, 1habcdefg
294 encoding: Optional[str] = None, 1habcdefg
295 errors: Optional[str] = "strict", 1habcdefg
296 lazy: Optional[bool] = None, 1habcdefg
297 atomic: bool = False, 1habcdefg
298 # Path
299 exists: bool = False, 1habcdefg
300 file_okay: bool = True, 1habcdefg
301 dir_okay: bool = True, 1habcdefg
302 writable: bool = False, 1habcdefg
303 readable: bool = True, 1habcdefg
304 resolve_path: bool = False, 1habcdefg
305 allow_dash: bool = False, 1habcdefg
306 path_type: Union[None, Type[str], Type[bytes]] = None, 1habcdefg
307 # Rich settings
308 rich_help_panel: Union[str, None] = None, 1habcdefg
309) -> Any: ... 1habcdefg
312# Overload for Argument created with custom type 'click_type'
313@overload 1habcdefg
314def Argument( 1abcdefg
315 # Parameter
316 default: Optional[Any] = ..., 1habcdefg
317 *,
318 callback: Optional[Callable[..., Any]] = None, 1habcdefg
319 metavar: Optional[str] = None, 1habcdefg
320 expose_value: bool = True, 1habcdefg
321 is_eager: bool = False, 1habcdefg
322 envvar: Optional[Union[str, List[str]]] = None, 1habcdefg
323 shell_complete: Optional[ 1abcdefg
324 Callable[ 1abcdefg
325 [click.Context, click.Parameter, str], 1abcdefg
326 Union[List["click.shell_completion.CompletionItem"], List[str]], 1abcdefg
327 ]
328 ] = None, 1habcdefg
329 autocompletion: Optional[Callable[..., Any]] = None, 1habcdefg
330 default_factory: Optional[Callable[[], Any]] = None, 1habcdefg
331 # Custom type
332 click_type: Optional[click.ParamType] = None, 1habcdefg
333 # TyperArgument
334 show_default: Union[bool, str] = True, 1habcdefg
335 show_choices: bool = True, 1habcdefg
336 show_envvar: bool = True, 1habcdefg
337 help: Optional[str] = None, 1habcdefg
338 hidden: bool = False, 1habcdefg
339 # Choice
340 case_sensitive: bool = True, 1habcdefg
341 # Numbers
342 min: Optional[Union[int, float]] = None, 1habcdefg
343 max: Optional[Union[int, float]] = None, 1habcdefg
344 clamp: bool = False, 1habcdefg
345 # DateTime
346 formats: Optional[List[str]] = None, 1habcdefg
347 # File
348 mode: Optional[str] = None, 1habcdefg
349 encoding: Optional[str] = None, 1habcdefg
350 errors: Optional[str] = "strict", 1habcdefg
351 lazy: Optional[bool] = None, 1habcdefg
352 atomic: bool = False, 1habcdefg
353 # Path
354 exists: bool = False, 1habcdefg
355 file_okay: bool = True, 1habcdefg
356 dir_okay: bool = True, 1habcdefg
357 writable: bool = False, 1habcdefg
358 readable: bool = True, 1habcdefg
359 resolve_path: bool = False, 1habcdefg
360 allow_dash: bool = False, 1habcdefg
361 path_type: Union[None, Type[str], Type[bytes]] = None, 1habcdefg
362 # Rich settings
363 rich_help_panel: Union[str, None] = None, 1habcdefg
364) -> Any: ... 1habcdefg
367def Argument( 1abcdefg
368 # Parameter
369 default: Optional[Any] = ...,
370 *,
371 callback: Optional[Callable[..., Any]] = None,
372 metavar: Optional[str] = None,
373 expose_value: bool = True,
374 is_eager: bool = False,
375 envvar: Optional[Union[str, List[str]]] = None,
376 shell_complete: Optional[
377 Callable[
378 [click.Context, click.Parameter, str],
379 Union[List["click.shell_completion.CompletionItem"], List[str]],
380 ]
381 ] = None,
382 autocompletion: Optional[Callable[..., Any]] = None,
383 default_factory: Optional[Callable[[], Any]] = None,
384 # Custom type
385 parser: Optional[Callable[[str], Any]] = None,
386 click_type: Optional[click.ParamType] = None,
387 # TyperArgument
388 show_default: Union[bool, str] = True,
389 show_choices: bool = True,
390 show_envvar: bool = True,
391 help: Optional[str] = None,
392 hidden: bool = False,
393 # Choice
394 case_sensitive: bool = True,
395 # Numbers
396 min: Optional[Union[int, float]] = None,
397 max: Optional[Union[int, float]] = None,
398 clamp: bool = False,
399 # DateTime
400 formats: Optional[List[str]] = None,
401 # File
402 mode: Optional[str] = None,
403 encoding: Optional[str] = None,
404 errors: Optional[str] = "strict",
405 lazy: Optional[bool] = None,
406 atomic: bool = False,
407 # Path
408 exists: bool = False,
409 file_okay: bool = True,
410 dir_okay: bool = True,
411 writable: bool = False,
412 readable: bool = True,
413 resolve_path: bool = False,
414 allow_dash: bool = False,
415 path_type: Union[None, Type[str], Type[bytes]] = None,
416 # Rich settings
417 rich_help_panel: Union[str, None] = None,
418) -> Any:
419 return ArgumentInfo( 1habcdefg
420 # Parameter
421 default=default,
422 # Arguments can only have one param declaration
423 # it will be generated from the param name
424 param_decls=None,
425 callback=callback,
426 metavar=metavar,
427 expose_value=expose_value,
428 is_eager=is_eager,
429 envvar=envvar,
430 shell_complete=shell_complete,
431 autocompletion=autocompletion,
432 default_factory=default_factory,
433 # Custom type
434 parser=parser,
435 click_type=click_type,
436 # TyperArgument
437 show_default=show_default,
438 show_choices=show_choices,
439 show_envvar=show_envvar,
440 help=help,
441 hidden=hidden,
442 # Choice
443 case_sensitive=case_sensitive,
444 # Numbers
445 min=min,
446 max=max,
447 clamp=clamp,
448 # DateTime
449 formats=formats,
450 # File
451 mode=mode,
452 encoding=encoding,
453 errors=errors,
454 lazy=lazy,
455 atomic=atomic,
456 # Path
457 exists=exists,
458 file_okay=file_okay,
459 dir_okay=dir_okay,
460 writable=writable,
461 readable=readable,
462 resolve_path=resolve_path,
463 allow_dash=allow_dash,
464 path_type=path_type,
465 # Rich settings
466 rich_help_panel=rich_help_panel,
467 )