forked from tilt-dev/tilt-extensions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTiltfile
More file actions
132 lines (112 loc) · 3.22 KB
/
Copy pathTiltfile
File metadata and controls
132 lines (112 loc) · 3.22 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
LOCATION_RESOURCE = 'resource'
LOCATION_NAV = 'nav'
location = struct(
RESOURCE = LOCATION_RESOURCE,
NAV = LOCATION_NAV,
)
def _button(name, location, text='', icon=None, annotations={}, inputs=[]):
text = text or name
btn = {
"apiVersion": "tilt.dev/v1alpha1",
"kind": "UIButton",
"metadata": {
"name": name,
"annotations": annotations
},
"spec": {
"text": text,
"location": {
"componentType": location.type,
"componentID": location.id,
}
}
}
if len(inputs):
btn["spec"]["inputs"] = inputs
if icon:
if icon.svg:
# convert to str to handle str + Blob
btn['spec']['iconSVG'] = str(icon.svg)
elif icon.name:
btn['spec']['iconName'] = icon.name
return btn
def cmd_button(name, resource='', argv=[], text=None, location=LOCATION_RESOURCE, icon_name=None, icon_svg=None, inputs=[]):
if config.tilt_subcommand == 'down':
return
if not location:
fail('location is required')
if location == LOCATION_RESOURCE:
if not resource:
fail('Must provide a resource name')
elif resource:
fail('Cannot specify resource for location type {}'.format(location))
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)
button = _button(
name=name,
location=location,
text=text,
icon=struct(name=icon_name, svg=icon_svg),
annotations=btn_annotations,
inputs=inputs,
)
cmd = {
"apiVersion": "tilt.dev/v1alpha1",
"kind": "Cmd",
"metadata": {
"name": "btn-" + name,
"annotations": {
"tilt.dev/resource": resource,
"tilt.dev/log-span-id": 'cmd:' + name,
}
},
"spec": {
"args": argv,
"dir": config.main_dir,
"startOn": {
"startAfter": _now(),
"uiButtons": [name],
},
}
}
local('echo "${TILT_APPLY_YAML}" | %s apply -f -' % (sys.executable,),
env={'TILT_APPLY_YAML': str(encode_yaml_stream([button, cmd]))},
echo_off=True)
def _now():
# this is portable across coreutils/busybox/BSD
# note: it's missing fractional seconds because that's not available from strftime
return str(local('date -u +"%Y-%m-%dT%H:%M:%S.000000Z"', echo_off=True, quiet=True)).rstrip('\r\n')
def text_input(name, label='', default='', placeholder=''):
return {
"name": name,
"label": label,
"text": {
"defaultValue": default,
"placeholder": placeholder,
}
}
def bool_input(name, label='', default=False, true_string=None, false_string=None):
result = {
"name": name,
"label": label,
"bool": {
"defaultValue": default,
},
}
if true_string != None:
result["bool"]["trueString"] = true_string
if false_string != None:
result["bool"]["falseString"] = false_string
return result