forked from apache/airflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
breeze-complete
334 lines (301 loc) · 11.9 KB
/
breeze-complete
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
#!/usr/bin/env bash
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# Allowed values for the commands & flags used
# The values here should be synchronized with the ones in
# the ./scripts/ci/libraries/_initialization.sh and it is verified
# Those cannot be made read-only as the breeze-complete must be re-sourceable
_breeze_allowed_python_major_minor_versions="3.7 3.8 3.9 3.10"
_breeze_allowed_backends="sqlite mysql postgres mssql"
_breeze_allowed_integrations="cassandra kerberos mongo openldap pinot rabbitmq redis statsd trino all"
_breeze_allowed_kubernetes_modes="image"
_breeze_allowed_kubernetes_versions="v1.24.2 v1.23.6 v1.22.9 v1.21.12 v1.20.15"
_breeze_allowed_helm_versions="v3.9.2"
_breeze_allowed_kind_versions="v0.14.0"
_breeze_allowed_mysql_versions="5.7 8"
_breeze_allowed_mssql_versions="2017-latest 2019-latest"
_breeze_allowed_postgres_versions="10 11 12 13 14"
_breeze_allowed_kind_operations="start stop restart status deploy test shell k9s"
_breeze_allowed_executors="KubernetesExecutor CeleryExecutor LocalExecutor CeleryKubernetesExecutor LocalKubernetesExecutor"
_breeze_allowed_test_types="All Always Core Providers API CLI Integration Other WWW Postgres MySQL Helm Quarantined"
# shellcheck disable=SC2034
{
# Default values for the commands & flags used
_breeze_default_backend=$(echo "${_breeze_allowed_backends}" | awk '{print $1}')
_breeze_default_kubernetes_mode=$(echo "${_breeze_allowed_kubernetes_modes}" | awk '{print $1}')
_breeze_default_kubernetes_version=$(echo "${_breeze_allowed_kubernetes_versions}" | awk '{print $1}')
_breeze_default_helm_version=$(echo "${_breeze_allowed_helm_versions}" | awk '{print $1}')
_breeze_default_kind_version=$(echo "${_breeze_allowed_kind_versions}" | awk '{print $1}')
_breeze_default_executor=$(echo "${_breeze_allowed_executors}" | awk '{print $1}')
_breeze_default_postgres_version=$(echo "${_breeze_allowed_postgres_versions}" | awk '{print $1}')
_breeze_default_mysql_version=$(echo "${_breeze_allowed_mysql_versions}" | awk '{print $1}')
_breeze_default_mssql_version=$(echo "${_breeze_allowed_mssql_versions}" | awk '{print $1}')
_breeze_default_test_type=$(echo "${_breeze_allowed_test_types}" | awk '{print $1}')
}
_breeze_allowed_USE_AIRFLOW_VERSION=$(cat <<-EOF
2.2.5
2.1.4
wheel
sdist
none
EOF
)
_breeze_default_github_repository="apache/airflow"
_breeze_default_github_image_id="latest"
_breeze_short_options="
h p: b: i:
K: V:
l a: t: d:
v y n q f
F P I E: C r
L U X
g: s:
S: N:
"
_breeze_long_options="
help python: backend: integration:
kubernetes-mode: kubernetes-version: helm-version: kind-version:
skip-mounting-local-sources mount-all-local-sources db-reset
verbose assume-yes assume-no assume-quit forward-credentials init-script:
github-repository: github-image-id:
postgres-version: mysql-version: mssql-version:
load-default-connections load-example-dags
use-airflow-version: test-type: preserve-volumes dry-run-docker executor:
"
_breeze_commands="
shell
exec
initialize-local-virtualenv
setup-autocomplete
start-airflow
stop
restart
toggle-suppress-cheatsheet
toggle-suppress-asciiart"
_breeze_extra_arg_commands="
docker-compose
kind-cluster
tests
"
_breeze_help_commands="
flags
help
help-all"
_breeze_all_commands="${_breeze_commands} ${_breeze_extra_arg_commands} ${_breeze_help_commands}"
# Note on OSX bash has no associative arrays (Bash 3.2) so we have to fake it
_breeze_known_values=""
#######################################################################################################
#
# Dynamically set list of values in _breeze_known_values variable depending on the command used
#
# Used variables:
# _breeze_allowed_* for allowed values for the commands
#
# Arguments:
# $1 - command to get known values for
#
# Set variables:
# _breeze_known_values is set to list of known values for the command, separated with space
#
#######################################################################################################
function breeze_complete::get_known_values_breeze() {
case "$1" in
-p | --python)
_breeze_known_values=${_breeze_allowed_python_major_minor_versions}
;;
-b | --backend)
_breeze_known_values=${_breeze_allowed_backends}
;;
-i | --integration)
_breeze_known_values=${_breeze_allowed_integrations}
;;
-K | --kubernetes-mode)
_breeze_known_values=${_breeze_allowed_kubernetes_modes}
;;
-V | --kubernetes-version)
_breeze_known_values=${_breeze_allowed_kubernetes_versions}
;;
--kind-version)
_breeze_known_values=${_breeze_allowed_kind_versions}
;;
--helm-version)
_breeze_known_values=${_breeze_allowed_helm_versions}
;;
--use-airflow-version)
_breeze_known_values=${_breeze_allowed_USE_AIRFLOW_VERSION}
;;
docker-compose)
# shellcheck disable=SC2034
if typeset -f "_docker_compose" >/dev/null; then
_docker_compose
fi
_breeze_known_values=""
;;
--postgres-version)
_breeze_known_values=${_breeze_allowed_postgres_versions}
;;
--mysql-version)
_breeze_known_values=${_breeze_allowed_mysql_versions}
;;
--mssql-version)
_breeze_known_values=${_breeze_allowed_mssql_versions}
;;
-g | --github-repository)
_breeze_known_values="${_breeze_default_github_repository}"
;;
kind-cluster)
_breeze_known_values="${_breeze_allowed_kind_operations}"
;;
tests)
_breeze_known_values="$(find tests -name '*.py')"
;;
--test-type)
_breeze_known_values="${_breeze_allowed_test_types}"
;;
--executor)
_breeze_known_values="${_breeze_allowed_executors}"
;;
*)
_breeze_known_values=""
;;
esac
}
_breeze_getopt_short_options=""
_breeze_getopt_long_options=""
#######################################################################################################
#
# Retrieves list of short and long options from the constants in the form of EOL separated values
# which is easy to maintain into comma separated list - usable for getopt.
#
# Used variables:
# _breeze_short_options
# _breeze_long_options
#
# Set variables:
# _breeze_getopt_short_options
# _breeze_getopt_long_options
#######################################################################################################
function breeze_complete::_build_options_breeze {
local separator=""
local option
for option in ${_breeze_short_options}
do
_breeze_getopt_short_options="${_breeze_getopt_short_options}${separator}${option}"
separator=","
done
separator=""
for option in ${_breeze_long_options}
do
_breeze_getopt_long_options="${_breeze_getopt_long_options}${separator}${option}"
separator=","
done
}
#######################################################################################################
#
# Returns 0 if word to check is in the list of words
# which is easy to maintain into comma separated list - usable for getopt.
#
# Arguments:
# $1 - space separated list of words
# $2 - word to look for
#
# Return:
# 0 - if the word is found in the list
# 1 - otherwise
#######################################################################################################
function breeze_complete::_listcontains_breeze {
local word
for word in $1; do
[[ ${word} = "$2" ]] && return 0
done
return 1
}
#######################################################################################################
#
# Convert options from the lists passed and add the options to appropriate variables.
# The options are stripped of the trailing colon and if they do have a colon, they are added
# to the options that require an argument. Options are prefixed with the prefix.
#
# Arguments:
# $1 - prefix for the option
# $2 - list of options
#
# Variables modified:
# all_options - space-separated all options
# options_with extra_args - space separate list of options with an extra argument
#######################################################################################################
function breeze_complete::_convert_options {
local option_with_prefix_without_colon
local option
local prefix=$1
for option in $2
do
last_character="${option:$((${#option} - 1)):1}"
option_with_prefix_without_colon=${prefix}${option//:/}
if [[ "${last_character}" == ":" ]]; then
options_with_extra_arguments="${options_with_extra_arguments} ${option_with_prefix_without_colon}"
fi
all_options="${all_options} ${option_with_prefix_without_colon}"
done
}
#######################################################################################################
#
# A completion function for breeze
#
# See: https://www.gnu.org/software/bash/manual/html_node/Programmable-Completion.html#Programmable-Completion
#
#######################################################################################################
function breeze_complete::_comp_breeze {
local all_options=""
local options_with_extra_arguments=""
local currently_typed_string
local previous_command_in_the_command_line
local last_character
breeze_complete::_convert_options "-" "${_breeze_short_options}"
breeze_complete::_convert_options "--" "${_breeze_long_options}"
# Add all Breeze commands to list of all options
all_options="${all_options} ${_breeze_all_commands}"
# Add all Breeze commands with extra args to list of options with extra args
options_with_extra_arguments="${options_with_extra_arguments} ${_breeze_extra_arg_commands}"
# Retrieve typed beginning of current commands used so that we can use it as filter in the compgen utility
currently_typed_string="${COMP_WORDS[${COMP_CWORD}]}"
# if we have already typed more words, then we check what was the last previous command so that
# we can retrieve list of known values matching it.
if [[ ${#COMP_WORDS[@]} -gt 1 ]]; then
previous_command_in_the_command_line="${COMP_WORDS[${COMP_CWORD} - 1]}"
else
previous_command_in_the_command_line=""
fi
# if the previous command is in the list of options with extra args - check what are the known values
if breeze_complete::_listcontains_breeze \
"${options_with_extra_arguments}" "${previous_command_in_the_command_line}"; then
# Set COMPREPLY containing list of valid values matching currently typed string from known values
COMPREPLY=()
breeze_complete::get_known_values_breeze "${previous_command_in_the_command_line}"
while IFS='' read -r line; do COMPREPLY+=("${line}"); done \
< <(compgen -W "${_breeze_known_values}" -- "${currently_typed_string}")
else
# Set COMPREPLY containing list of valid commands/options matching currently typed string
COMPREPLY=()
while IFS='' read -r line; do COMPREPLY+=("${line}"); done \
< <(compgen -W "${all_options}" -- "${currently_typed_string}")
fi
}
breeze_complete::_build_options_breeze
# set autocompletion function for breeze
complete -F breeze_complete::_comp_breeze breeze-legacy
complete -F breeze_complete::_comp_breeze ./breeze-legacy