-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.py
executable file
·104 lines (76 loc) · 1.82 KB
/
example.py
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
#!/usr/bin/env python3
from typing import Sequence
import click
# import rich_click as click
from click_prompt import choice_option
from click_prompt import confirm_option
from click_prompt import filepath_option
from click_prompt import auto_complete_option
from click_prompt import choice_argument
FRUITS = [
"Apples",
"Bananas",
"Grapefruits",
"Mangoes",
"Oranges",
"Pears",
"Peaches",
"Raspberries",
"Strawberries",
"Watermelons",
]
@click.group()
def cli(**kwargs):
pass
@cli.command()
@choice_option(
"--fruit",
type=click.Choice(FRUITS),
prompt="What do you want to eat?",
default=FRUITS[3],
)
def single(fruit: str):
print(fruit)
def get_fruits():
return FRUITS[3:6] + FRUITS[7:8]
@cli.command()
@choice_option(
"--fruit",
prompt="Select smoothie ingredients",
type=click.Choice(FRUITS),
multiple=True,
default=get_fruits,
)
def multiple(fruit: Sequence[str]):
print(fruit)
@cli.command()
@confirm_option("--confirm", prompt="Do you really want to ?")
def confirm(confirm: bool):
print(confirm)
@cli.command()
@click.option("--confirm", prompt="Confirm", is_flag=True)
def confirm_click(confirm: bool):
print(confirm)
@cli.command()
@filepath_option("--path", default="/tmp/foo")
def file(path: str):
print(path)
@cli.command()
@auto_complete_option("--fruit", type=click.Choice(FRUITS), default="r")
def auto_choice(fruit: str):
"""
Select a fruit from a list by typing
"""
print(fruit)
@cli.command()
@auto_complete_option(
"--complete", prompt="What is your favourite fruit?", choices=FRUITS, default="m"
)
def auto(complete: str):
print(complete)
@cli.command()
@choice_argument("fruit", type=click.Choice(FRUITS))
def argument(fruit: str):
print(fruit)
if __name__ == "__main__":
cli()