-
Notifications
You must be signed in to change notification settings - Fork 169
/
Tiltfile
81 lines (64 loc) · 2.71 KB
/
Tiltfile
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
LOCATION_RESOURCE = 'resource'
LOCATION_NAV = 'nav'
location = struct(
RESOURCE=LOCATION_RESOURCE,
NAV=LOCATION_NAV,
)
valid_subcommands = ['up', 'ci']
def cmd_button(name, resource='', argv=[], text=None,
location=LOCATION_RESOURCE, icon_name=None, icon_svg=None,
inputs=[], disabled=False, requires_confirmation=False, env=[],
dir=config.main_dir):
if config.tilt_subcommand not in valid_subcommands:
return
if not location:
fail('location is required')
if not resource:
if location == LOCATION_RESOURCE:
fail('Must provide a resource name')
else:
# for nav buttons, default logs to Tiltfile if no resource specified
resource = '(Tiltfile)'
if not argv:
fail('argv cannot be empty')
btn_annotations = {}
if location == LOCATION_NAV:
location = struct(type='Global', id='nav')
elif location == LOCATION_RESOURCE:
location = struct(type='Resource', id=resource)
btn_annotations['tilt.dev/resource'] = resource
else:
# fallback to simplify experimenting with new locations in the future
loc_type, sep, loc_id = location.partition('/')
if not sep:
fail('Unsupported location {}'.format(location))
location = struct(type=loc_type, id=loc_id)
text = text or name
v1alpha1.ui_button(
name=name,
location={
"component_type": location.type,
"component_id": location.id,
},
text=text,
icon_name=icon_name or '',
icon_svg=str(icon_svg) if icon_svg else '',
annotations=btn_annotations,
inputs=inputs,
disabled=disabled,
requires_confirmation=requires_confirmation,
)
v1alpha1.cmd(name="btn-" + name, annotations={
"tilt.dev/resource": resource,
"tilt.dev/log-span-id": 'cmd:' + name,
}, args=argv, dir=dir, env=env, start_on=v1alpha1.start_on_spec(ui_buttons=[name]))
def text_input(name, label='', default='', placeholder=''):
return v1alpha1.ui_input_spec(name=name, label=label,
text=v1alpha1.ui_text_input_spec(default_value=default, placeholder=placeholder))
def bool_input(name, label='', default=False, true_string=None,
false_string=None):
return v1alpha1.ui_input_spec(name=name, label=label,
bool=v1alpha1.ui_bool_input_spec(default_value=default, true_string=true_string, false_string=false_string))
def choice_input(name, label='', choices=[]):
return v1alpha1.ui_input_spec(name=name, label=label,
choice=v1alpha1.ui_choice_input_spec(choices=choices))