-
-
Notifications
You must be signed in to change notification settings - Fork 889
Expand file tree
/
Copy pathparams.py
More file actions
1831 lines (1621 loc) · 58.3 KB
/
params.py
File metadata and controls
1831 lines (1621 loc) · 58.3 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
from collections.abc import Callable
from typing import TYPE_CHECKING, Annotated, Any, overload
import click
from annotated_doc import Doc
from .models import ArgumentInfo, OptionInfo
if TYPE_CHECKING: # pragma: no cover
import click.shell_completion
# Overload for Option created with custom type 'parser'
@overload
def Option(
# Parameter
default: Any | None = ...,
*param_decls: str,
callback: Callable[..., Any] | None = None,
metavar: str | None = None,
expose_value: bool = True,
is_eager: bool = False,
envvar: str | list[str] | None = None,
# Note that shell_complete is not fully supported and will be removed in future versions
# TODO: Remove shell_complete in a future version (after 0.16.0)
shell_complete: Callable[
[click.Context, click.Parameter, str],
list["click.shell_completion.CompletionItem"] | list[str],
]
| None = None,
autocompletion: Callable[..., Any] | None = None,
default_factory: Callable[[], Any] | None = None,
# Custom type
parser: Callable[[str], Any] | None = None,
# Option
show_default: bool | str = True,
prompt: bool | str = False,
confirmation_prompt: bool = False,
prompt_required: bool = True,
hide_input: bool = False,
# TODO: remove is_flag and flag_value in a future release
is_flag: bool | None = None,
flag_value: Any | None = None,
count: bool = False,
allow_from_autoenv: bool = True,
help: str | None = None,
hidden: bool = False,
show_choices: bool = True,
show_envvar: bool = True,
# Choice
case_sensitive: bool = True,
# Numbers
min: int | float | None = None,
max: int | float | None = None,
clamp: bool = False,
# DateTime
formats: list[str] | None = None,
# File
mode: str | None = None,
encoding: str | None = None,
errors: str | None = "strict",
lazy: bool | None = None,
atomic: bool = False,
# Path
exists: bool = False,
file_okay: bool = True,
dir_okay: bool = True,
writable: bool = False,
readable: bool = True,
resolve_path: bool = False,
allow_dash: bool = False,
path_type: None | type[str] | type[bytes] = None,
# Rich settings
rich_help_panel: str | None = None,
) -> Any: ...
# Overload for Option created with custom type 'click_type'
@overload
def Option(
# Parameter
default: Any | None = ...,
*param_decls: str,
callback: Callable[..., Any] | None = None,
metavar: str | None = None,
expose_value: bool = True,
is_eager: bool = False,
envvar: str | list[str] | None = None,
# Note that shell_complete is not fully supported and will be removed in future versions
# TODO: Remove shell_complete in a future version (after 0.16.0)
shell_complete: Callable[
[click.Context, click.Parameter, str],
list["click.shell_completion.CompletionItem"] | list[str],
]
| None = None,
autocompletion: Callable[..., Any] | None = None,
default_factory: Callable[[], Any] | None = None,
# Custom type
click_type: click.ParamType | None = None,
# Option
show_default: bool | str = True,
prompt: bool | str = False,
confirmation_prompt: bool = False,
prompt_required: bool = True,
hide_input: bool = False,
# TODO: remove is_flag and flag_value in a future release
is_flag: bool | None = None,
flag_value: Any | None = None,
count: bool = False,
allow_from_autoenv: bool = True,
help: str | None = None,
hidden: bool = False,
show_choices: bool = True,
show_envvar: bool = True,
# Choice
case_sensitive: bool = True,
# Numbers
min: int | float | None = None,
max: int | float | None = None,
clamp: bool = False,
# DateTime
formats: list[str] | None = None,
# File
mode: str | None = None,
encoding: str | None = None,
errors: str | None = "strict",
lazy: bool | None = None,
atomic: bool = False,
# Path
exists: bool = False,
file_okay: bool = True,
dir_okay: bool = True,
writable: bool = False,
readable: bool = True,
resolve_path: bool = False,
allow_dash: bool = False,
path_type: None | type[str] | type[bytes] = None,
# Rich settings
rich_help_panel: str | None = None,
) -> Any: ...
def Option(
# Parameter
default: Annotated[
Any | None,
Doc(
"""
Usually, [CLI options](https://typer.tiangolo.com/tutorial/options/) are optional and have a default value, passed on like this:
**Example**
```python
@app.command()
def main(network: str = typer.Option("CNN")):
print(f"Training neural network of type: {network}")
```
Note that this usage is deprecated, and we recommend to use `Annotated` instead:
```
@app.command()
def main(network: Annotated[str, typer.Option()] = "CNN"):
print(f"Hello {name}!")
```
You can also use `...` ([Ellipsis](https://docs.python.org/3/library/constants.html#Ellipsis)) as the "default" value to clarify that this is a required CLI option.
"""
),
] = ...,
*param_decls: Annotated[
str,
Doc(
"""
Positional argument that defines how users can call this option on the command line. This may be one or multiple aliases, all strings.
If not defined, Typer will automatically use the function parameter as default name.
See [the tutorial about CLI Option Names](https://typer.tiangolo.com/tutorial/options/name/) for more details.
**Example**
```python
@app.command()
def main(user_name: Annotated[str, typer.Option("--user", "-u", "-x")]):
print(f"Hello {user_name}")
```
"""
),
],
callback: Annotated[
Callable[..., Any] | None,
Doc(
"""
Add a callback to this CLI Option, to execute additional logic after its value was received from the terminal.
See [the tutorial about callbacks](https://typer.tiangolo.com/tutorial/options/callback-and-context/) for more details.
**Example**
```python
def name_callback(value: str):
if value != "Deadpool":
raise typer.BadParameter("Only Deadpool is allowed")
return value
@app.command()
def main(name: Annotated[str, typer.Option(callback=name_callback)]):
print(f"Hello {name}")
```
"""
),
] = None,
metavar: Annotated[
str | None,
Doc(
"""
Customize the name displayed in the [help text](https://typer.tiangolo.com/tutorial/options/help/) to represent this CLI option.
Note that this doesn't influence the way the option must be called.
**Example**
```python
@app.command()
def main(user: Annotated[str, typer.Option(metavar="User name")]):
print(f"Hello {user}")
```
"""
),
] = None,
expose_value: Annotated[
bool,
Doc(
"""
**Note**: you probably shouldn't use this parameter, it is inherited from Click and supported for compatibility.
---
If this is `True` then the value is passed onwards to the command callback and stored on the context, otherwise it’s skipped.
"""
),
] = True,
is_eager: Annotated[
bool,
Doc(
"""
Mark a CLI Option to be "eager", ensuring it gets processed before other CLI parameters. This could be relevant when there are other parameters with callbacks that could exit the program early.
For more information and an extended example, see the documentation [here](https://typer.tiangolo.com/tutorial/options/version/#fix-with-is_eager).
"""
),
] = False,
envvar: Annotated[
str | list[str] | None,
Doc(
"""
Configure a CLI Option to read its value from an environment variable if it is not provided in the command line.
For more information, see the [documentation on Environment Variables](https://typer.tiangolo.com/tutorial/arguments/envvar/).
**Example**
```python
@app.command()
def main(user: Annotated[str, typer.Option(envvar="ME")]):
print(f"Hello {user}")
```
"""
),
] = None,
# TODO: Remove shell_complete in a future version (after 0.16.0)
shell_complete: Annotated[
Callable[
[click.Context, click.Parameter, str],
list["click.shell_completion.CompletionItem"] | list[str],
]
| None,
Doc(
"""
**Note**: you probably shouldn't use this parameter, it is inherited from Click and supported for compatibility.
It is however not fully functional, and will likely be removed in future versions.
"""
),
] = None,
autocompletion: Annotated[
Callable[..., Any] | None,
Doc(
"""
Provide a custom function that helps to autocomplete the values of this CLI Option.
See [the tutorial on parameter autocompletion](https://typer.tiangolo.com/tutorial/options-autocompletion) for more details.
**Example**
```python
def complete():
return ["Me", "Myself", "I"]
@app.command()
def main(name: Annotated[str, typer.Option(autocompletion=complete)]):
print(f"Hello {name}")
```
"""
),
] = None,
default_factory: Annotated[
Callable[[], Any] | None,
Doc(
"""
Provide a custom function that dynamically generates a [default](https://typer.tiangolo.com/tutorial/arguments/default) for this CLI Option.
**Example**
```python
def get_name():
return random.choice(["Me", "Myself", "I"])
@app.command()
def main(name: Annotated[str, typer.Option(default_factory=get_name)]):
print(f"Hello {name}")
```
"""
),
] = None,
# Custom type
parser: Annotated[
Callable[[str], Any] | None,
Doc(
"""
Use your own custom types in Typer applications by defining a `parser` function that parses input into your own types:
**Example**
```python
class CustomClass:
def __init__(self, value: str):
self.value = value
def __str__(self):
return f"<CustomClass: value={self.value}>"
def my_parser(value: str):
return CustomClass(value * 2)
@app.command()
def main(opt: Annotated[CustomClass, typer.Option(parser=my_parser)] = "Foo"):
print(f"--opt is {opt}")
```
"""
),
] = None,
click_type: Annotated[
click.ParamType | None,
Doc(
"""
Define this parameter to use a [custom Click type](https://click.palletsprojects.com/en/stable/parameters/#implementing-custom-types) in your Typer applications.
**Example**
```python
class MyClass:
def __init__(self, value: str):
self.value = value
def __str__(self):
return f"<MyClass: value={self.value}>"
class MyParser(click.ParamType):
name = "MyClass"
def convert(self, value, param, ctx):
return MyClass(value * 3)
@app.command()
def main(opt: Annotated[MyClass, typer.Option(click_type=MyParser())] = "Foo"):
print(f"--opt is {opt}")
```
"""
),
] = None,
# Option
show_default: Annotated[
bool | str,
Doc(
"""
When set to `False`, don't show the default value of this CLI Option in the [help text](https://typer.tiangolo.com/tutorial/options/help/).
**Example**
```python
@app.command()
def main(name: Annotated[str, typer.Option(show_default=False)] = "Rick"):
print(f"Hello {name}")
```
"""
),
] = True,
prompt: Annotated[
bool | str,
Doc(
"""
When set to `True`, a prompt will appear to ask for the value of this CLI Option if it was not provided:
**Example**
```python
@app.command()
def main(name: str, lastname: Annotated[str, typer.Option(prompt=True)]):
print(f"Hello {name} {lastname}")
```
"""
),
] = False,
confirmation_prompt: Annotated[
bool,
Doc(
"""
When set to `True`, a user will need to type a prompted value twice (may be useful for passwords etc.).
**Example**
```python
@app.command()
def main(project: Annotated[str, typer.Option(prompt=True, confirmation_prompt=True)]):
print(f"Deleting project {project}")
```
"""
),
] = False,
prompt_required: Annotated[
bool,
Doc(
"""
**Note**: you probably shouldn't use this parameter, it is inherited from Click and supported for compatibility.
---
If this is `False` then a prompt is only shown if the option's flag is given without a value.
"""
),
] = True,
hide_input: Annotated[
bool,
Doc(
"""
When you've configured a prompt, for instance for [querying a password](https://typer.tiangolo.com/tutorial/options/password/),
don't show anything on the screen while the user is typing the value.
**Example**
```python
@app.command()
def login(
name: str,
password: Annotated[str, typer.Option(prompt=True, hide_input=True)],
):
print(f"Hello {name}. Doing something very secure with password.")
```
"""
),
] = False,
# TODO: remove is_flag and flag_value in a future release
is_flag: Annotated[
bool | None,
Doc(
"""
**Note**: you probably shouldn't use this parameter, it is inherited from Click and supported for compatibility.
It is however not fully functional, and will likely be removed in future versions.
"""
),
] = None,
flag_value: Annotated[
Any | None,
Doc(
"""
**Note**: you probably shouldn't use this parameter, it is inherited from Click and supported for compatibility.
It is however not fully functional, and will likely be removed in future versions.
"""
),
] = None,
count: Annotated[
bool,
Doc(
"""
Make a CLI Option work as a [counter](https://typer.tiangolo.com/tutorial/parameter-types/number/#counter-cli-options).
The CLI option will have the `int` value representing the number of times the option was used on the command line.
**Example**
```python
@app.command()
def main(verbose: Annotated[int, typer.Option("--verbose", "-v", count=True)] = 0):
print(f"Verbose level is {verbose}")
```
"""
),
] = False,
allow_from_autoenv: Annotated[
bool,
Doc(
"""
**Note**: you probably shouldn't use this parameter, it is inherited from Click and supported for compatibility.
---
If this is enabled then the value of this parameter will be pulled from an environment variable in case a prefix is defined on the context.
"""
),
] = True,
help: Annotated[
str | None,
Doc(
"""
Help text for this CLI Option.
See [the tutorial about CLI Options with help](https://typer.tiangolo.com/tutorial/options/help/) for more dedails.
**Example**
```python
@app.command()
def greet(name: Annotated[str, typer.Option(help="Person to greet")] = "Deadpool"):
print(f"Hello {name}")
```
"""
),
] = None,
hidden: Annotated[
bool,
Doc(
"""
Hide this CLI Option from [help outputs](https://typer.tiangolo.com/tutorial/options/help). `False` by default.
**Example**
```python
@app.command()
def greet(name: Annotated[str, typer.Option(hidden=True)] = "Deadpool"):
print(f"Hello {name}")
```
"""
),
] = False,
show_choices: Annotated[
bool,
Doc(
"""
**Note**: you probably shouldn't use this parameter, it is inherited from Click and supported for compatibility.
---
When set to `False`, this suppresses choices from being displayed inline when `prompt` is used.
"""
),
] = True,
show_envvar: Annotated[
bool,
Doc(
"""
When an ["envvar"](https://typer.tiangolo.com/tutorial/arguments/envvar) is defined, prevent it from showing up in the help text:
**Example**
```python
@app.command()
def main(user: Annotated[str, typer.Option(envvar="ME", show_envvar=False)]):
print(f"Hello {user}")
```
"""
),
] = True,
# Choice
case_sensitive: Annotated[
bool,
Doc(
"""
For a CLI Option representing an [Enum (choice)](https://typer.tiangolo.com/tutorial/parameter-types/enum),
you can allow case-insensitive matching with this parameter:
**Example**
```python
from enum import Enum
class NeuralNetwork(str, Enum):
simple = "simple"
conv = "conv"
lstm = "lstm"
@app.command()
def main(
network: Annotated[NeuralNetwork, typer.Option(case_sensitive=False)]):
print(f"Training neural network of type: {network.value}")
```
With this setting, "LSTM" or "lstm" will both be valid values that will be resolved to `NeuralNetwork.lstm`.
"""
),
] = True,
# Numbers
min: Annotated[
int | float | None,
Doc(
"""
For a CLI Option representing a [number](https://typer.tiangolo.com/tutorial/parameter-types/number/) (`int` or `float`),
you can define numeric validations with `min` and `max` values:
**Example**
```python
@app.command()
def main(
user: Annotated[str, typer.Argument()],
user_id: Annotated[int, typer.Option(min=1, max=1000)],
):
print(f"ID for {user} is {user_id}")
```
If the user attempts to input an invalid number, an error will be shown, explaining why the value is invalid.
"""
),
] = None,
max: Annotated[
int | float | None,
Doc(
"""
For a CLI Option representing a [number](https://typer.tiangolo.com/tutorial/parameter-types/number/) (`int` or `float`),
you can define numeric validations with `min` and `max` values:
**Example**
```python
@app.command()
def main(
user: Annotated[str, typer.Argument()],
user_id: Annotated[int, typer.Option(min=1, max=1000)],
):
print(f"ID for {user} is {user_id}")
```
If the user attempts to input an invalid number, an error will be shown, explaining why the value is invalid.
"""
),
] = None,
clamp: Annotated[
bool,
Doc(
"""
For a CLI Option representing a [number](https://typer.tiangolo.com/tutorial/parameter-types/number/) and that is bounded by using `min` and/or `max`,
you can opt to use the closest minimum or maximum value instead of raising an error when the value is out of bounds. This is done by setting `clamp` to `True`.
**Example**
```python
@app.command()
def main(
user: Annotated[str, typer.Argument()],
user_id: Annotated[int, typer.Option(min=1, max=1000, clamp=True)],
):
print(f"ID for {user} is {user_id}")
```
If the user attempts to input 3420 for `user_id`, this will internally be converted to `1000`.
"""
),
] = False,
# DateTime
formats: Annotated[
list[str] | None,
Doc(
"""
For a CLI Option representing a [DateTime object](https://typer.tiangolo.com/tutorial/parameter-types/datetime),
you can customize the formats that can be parsed automatically:
**Example**
```python
from datetime import datetime
@app.command()
def main(
birthday: Annotated[
datetime,
typer.Option(
formats=["%Y-%m-%d", "%Y-%m-%d %H:%M:%S", "%m/%d/%Y"]
),
],
):
print(f"Birthday defined at: {birthday}")
```
"""
),
] = None,
# File
mode: Annotated[
str | None,
Doc(
"""
For a CLI Option representing a [File object](https://typer.tiangolo.com/tutorial/parameter-types/file/),
you can customize the mode to open the file with. If unset, Typer will set a [sensible value by default](https://typer.tiangolo.com/tutorial/parameter-types/file/#advanced-mode).
**Example**
```python
@app.command()
def main(config: Annotated[typer.FileText, typer.Option(mode="a")]):
config.write("This is a single line\\n")
print("Config line written")
```
"""
),
] = None,
encoding: Annotated[
str | None,
Doc(
"""
Customize the encoding of this CLI Option represented by a [File object](https://typer.tiangolo.com/tutorial/parameter-types/file/).
**Example**
```python
@app.command()
def main(config: Annotated[typer.FileText, typer.Option(encoding="utf-8")]):
config.write("All the text gets written\\n")
```
"""
),
] = None,
errors: Annotated[
str | None,
Doc(
"""
**Note**: you probably shouldn't use this parameter, it is inherited from Click and supported for compatibility.
---
The error handling mode.
"""
),
] = "strict",
lazy: Annotated[
bool | None,
Doc(
"""
For a CLI Option representing a [File object](https://typer.tiangolo.com/tutorial/parameter-types/file/),
by default the file will not be created until you actually start writing to it.
You can change this behaviour by setting this parameter.
By default, it's set to `True` for writing and to `False` for reading.
**Example**
```python
@app.command()
def main(config: Annotated[typer.FileText, typer.Option(mode="a", lazy=False)]):
config.write("This is a single line\\n")
print("Config line written")
```
"""
),
] = None,
atomic: Annotated[
bool,
Doc(
"""
For a CLI Option representing a [File object](https://typer.tiangolo.com/tutorial/parameter-types/file/),
you can ensure that all write instructions first go into a temporal file, and are only moved to the final destination after completing
by setting `atomic` to `True`. This can be useful for files with potential concurrent access.
**Example**
```python
@app.command()
def main(config: Annotated[typer.FileText, typer.Option(mode="a", atomic=True)]):
config.write("All the text")
```
"""
),
] = False,
# Path
exists: Annotated[
bool,
Doc(
"""
When set to `True` for a [`Path` CLI Option](https://typer.tiangolo.com/tutorial/parameter-types/path/),
additional validation is performed to check that the file or directory exists. If not, the value will be invalid.
**Example**
```python
from pathlib import Path
@app.command()
def main(config: Annotated[Path, typer.Option(exists=True)]):
text = config.read_text()
print(f"Config file contents: {text}")
```
"""
),
] = False,
file_okay: Annotated[
bool,
Doc(
"""
Determine whether or not a [`Path` CLI Option](https://typer.tiangolo.com/tutorial/parameter-types/path/)
is allowed to refer to a file. When this is set to `False`, the application will raise a validation error when a path to a file is given.
**Example**
```python
from pathlib import Path
@app.command()
def main(config: Annotated[Path, typer.Option(exists=True, file_okay=False)]):
print(f"Directory listing: {[x.name for x in config.iterdir()]}")
```
"""
),
] = True,
dir_okay: Annotated[
bool,
Doc(
"""
Determine whether or not a [`Path` CLI Option](https://typer.tiangolo.com/tutorial/parameter-types/path/)
is allowed to refer to a directory. When this is set to `False`, the application will raise a validation error when a path to a directory is given.
**Example**
```python
from pathlib import Path
@app.command()
def main(config: Annotated[Path, typer.Argument(exists=True, dir_okay=False)]):
text = config.read_text()
print(f"Config file contents: {text}")
```
"""
),
] = True,
writable: Annotated[
bool,
Doc(
"""
Whether or not to perform a writable check for this [`Path` CLI Option](https://typer.tiangolo.com/tutorial/parameter-types/path/).
**Example**
```python
from pathlib import Path
@app.command()
def main(config: Annotated[Path, typer.Option(writable=True)]):
config.write_text("All the text")
```
"""
),
] = False,
readable: Annotated[
bool,
Doc(
"""
Whether or not to perform a readable check for this [`Path` CLI Option](https://typer.tiangolo.com/tutorial/parameter-types/path/).
**Example**
```python
from pathlib import Path
@app.command()
def main(config: Annotated[Path, typer.Option(readable=True)]):
config.read_text("All the text")
```
"""
),
] = True,
resolve_path: Annotated[
bool,
Doc(
"""
Whether or not to fully resolve the path of this [`Path` CLI Option](https://typer.tiangolo.com/tutorial/parameter-types/path/),
meaning that the path becomes absolute and symlinks are resolved.
**Example**
```python
from pathlib import Path
@app.command()
def main(config: Annotated[Path, typer.Option(resolve_path=True)]):
config.read_text("All the text")
```
"""
),
] = False,
allow_dash: Annotated[
bool,
Doc(
"""
When set to `True`, a single dash for this [`Path` CLI Option](https://typer.tiangolo.com/tutorial/parameter-types/path/)
would be a valid value, indicating standard streams. This is a more advanced use-case.
"""
),
] = False,
path_type: Annotated[
None | type[str] | type[bytes],
Doc(
"""
A string type that will be used to represent this [`Path` argument](https://typer.tiangolo.com/tutorial/parameter-types/path/).
The default is `None` which means the return value will be either bytes or unicode, depending on what makes most sense given the input data.
This is a more advanced use-case.
"""
),
] = None,
# Rich settings
rich_help_panel: Annotated[
str | None,
Doc(
"""
Set the panel name where you want this CLI Option to be shown in the [help text](https://typer.tiangolo.com/tutorial/arguments/help).
**Example**
```python
@app.command()
def main(
name: Annotated[str, typer.Argument(help="Who to greet")],
age: Annotated[str, typer.Option(help="Their age", rich_help_panel="Data")],
):
print(f"Hello {name} of age {age}")
```
"""
),
] = None,
) -> Any:
"""
A [CLI Option](https://typer.tiangolo.com/tutorial/options) is a parameter to your command line application that is called with a single or double dash, something like `--verbose` or `-v`.
Often, CLI Options are optional, meaning that users can omit them from the command. However, you can set them to be required by using `Annotated`
and omitting a default value.
## Example
```python
@app.command()
def register(
user: Annotated[str, typer.Argument()],
age: Annotated[int, typer.Option(min=18)],
):
print(f"User is {user}")
print(f"--age is {age}")
```
Note how in this example, `--age` is a required CLI Option.
"""
return OptionInfo(
# Parameter
default=default,
param_decls=param_decls,
callback=callback,
metavar=metavar,
expose_value=expose_value,
is_eager=is_eager,
envvar=envvar,
shell_complete=shell_complete,
autocompletion=autocompletion,
default_factory=default_factory,
# Custom type
parser=parser,
click_type=click_type,
# Option
show_default=show_default,
prompt=prompt,
confirmation_prompt=confirmation_prompt,
prompt_required=prompt_required,
hide_input=hide_input,
is_flag=is_flag,
flag_value=flag_value,
count=count,
allow_from_autoenv=allow_from_autoenv,
help=help,
hidden=hidden,
show_choices=show_choices,
show_envvar=show_envvar,
# Choice
case_sensitive=case_sensitive,
# Numbers
min=min,
max=max,
clamp=clamp,
# DateTime
formats=formats,
# File
mode=mode,
encoding=encoding,
errors=errors,
lazy=lazy,
atomic=atomic,
# Path
exists=exists,
file_okay=file_okay,
dir_okay=dir_okay,
writable=writable,
readable=readable,
resolve_path=resolve_path,
allow_dash=allow_dash,
path_type=path_type,
# Rich settings
rich_help_panel=rich_help_panel,
)