This repository has been archived by the owner on Apr 3, 2024. It is now read-only.
forked from apache/airflow
-
Notifications
You must be signed in to change notification settings - Fork 28
/
breeze-complete
457 lines (423 loc) · 15.4 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
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
#!/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
# by the BATS tests automatically during pre-commit and CI
# Those cannot be made read-only as the breeze-complete must be re-sourceable
_breeze_allowed_python_major_minor_versions="2.7 3.5 3.6 3.7 3.8"
_breeze_allowed_backends="sqlite mysql postgres"
_breeze_allowed_integrations="cassandra kerberos mongo openldap pinot rabbitmq redis statsd trino all"
_breeze_allowed_generate_constraints_modes="source-providers pypi-providers no-providers"
# registrys is good here even if it is not correct english. We are adding s automatically to all variables
_breeze_allowed_github_registrys="docker.pkg.github.com ghcr.io"
_breeze_allowed_kubernetes_modes="image"
_breeze_allowed_kubernetes_versions="v1.20.2 v1.19.7 v1.18.15"
_breeze_allowed_helm_versions="v3.2.4"
_breeze_allowed_kind_versions="v0.10.0"
_breeze_allowed_mysql_versions="5.7 8"
_breeze_allowed_postgres_versions="9.6 10 11 12 13"
_breeze_allowed_kind_operations="start stop restart status deploy test shell k9s"
_breeze_allowed_test_types="All Core Providers API CLI Integration Other WWW Postgres MySQL Helm Quarantined"
_breeze_allowed_package_formats="both sdist wheel"
_breeze_allowed_installation_methods=". apache-airflow"
# shellcheck disable=SC2034
{
# Default values for the commands & flags used
_breeze_default_backend=$(echo "${_breeze_allowed_backends}" | awk '{print $1}')
_breeze_default_github_registry=$(echo "${_breeze_allowed_github_registrys}" | awk '{print $1}')
_breeze_default_generate_providers_mode=$(echo "${_breeze_allowed_generate_constraints_modes}" | 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_postgres_version=$(echo "${_breeze_allowed_postgres_versions}" | awk '{print $1}')
_breeze_default_mysql_version=$(echo "${_breeze_allowed_mysql_versions}" | awk '{print $1}')
_breeze_default_test_type=$(echo "${_breeze_allowed_test_types}" | awk '{print $1}')
_breeze_default_package_format=$(echo "${_breeze_allowed_package_formats}" | awk '{print $1}')
}
_breeze_allowed_install_airflow_versions=$(cat <<-EOF
2.0.1
2.0.0
1.10.15
1.10.14
1.10.12
1.10.11
1.10.10
1.10.9
none
wheel
sdist
EOF
)
_breeze_allowed_static_checks=$(cat <<-EOF
all
all-but-pylint
airflow-config-yaml
airflow-providers-available
airflow-provider-yaml-files-ok
base-operator
bats-tests
bats-in-container-tests
black
build
build-providers-dependencies
check-apache-license
check-builtin-literals
check-executables-have-shebangs
check-hooks-apply
check-integrations
check-merge-conflict
check-xml
consistent-pylint
daysago-import-check
debug-statements
detect-private-key
doctoc
dont-use-safe-filter
end-of-file-fixer
fix-encoding-pragma
flake8
forbid-tabs
helm-lint
identity
incorrect-use-of-LoggingMixin
insert-license
isort
json-schema
language-matters
lint-dockerfile
lint-openapi
markdownlint
mermaid
mixed-line-ending
mypy
mypy-helm
no-providers-in-core-examples
no-relative-imports
pre-commit-descriptions
pre-commit-hook-names
provide-create-sessions
providers-init-file
provider-yamls
pydevd
pydocstyle
pylint
pylint-tests
python-no-log-warn
pyupgrade
restrict-start_date
rst-backticks
setup-order
setup-extra-packages
shellcheck
sort-in-the-wild
sort-spelling-wordlist
stylelint
trailing-whitespace
update-breeze-file
update-extras
update-local-yml-file
update-setup-cfg-file
version-sync
yamllint
EOF
)
_breeze_default_dockerhub_user="apache"
_breeze_default_dockerhub_repo="airflow"
_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
D: R: c 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 install-airflow-version: install-airflow-reference: db-reset
verbose assume-yes assume-no assume-quit forward-credentials init-script:
force-build-images force-pull-images force-pull-base-python-image production-image extras: force-clean-images skip-rebuild-check
build-cache-local build-cache-pulled build-cache-disabled disable-pip-cache
dockerhub-user: dockerhub-repo: use-github-registry github-registry: github-repository: github-image-id: generate-constraints-mode:
postgres-version: mysql-version:
version-suffix-for-pypi: version-suffix-for-svn:
additional-extras: additional-python-deps: additional-dev-deps: additional-runtime-deps: image-tag:
disable-mysql-client-installation constraints-location: disable-pip-cache install-from-docker-context-files
additional-extras: additional-python-deps: disable-pypi-when-building skip-installing-airflow-providers-from-sources
dev-apt-deps: additional-dev-apt-deps: dev-apt-command: additional-dev-apt-command: additional-dev-apt-env:
runtime-apt-deps: additional-runtime-apt-deps: runtime-apt-command: additional-runtime-apt-command: additional-runtime-apt-env:
load-default-connections load-example-dags
install-packages-from-dist no-rbac-ui package-format: upgrade-to-newer-dependencies installation-method: continue-on-pip-check-failure
test-type: preserve-volumes dry-run-docker
"
_breeze_commands="
shell
build-docs
build-image
cleanup-image
exec
generate-constraints
push-image
initialize-local-virtualenv
prepare-airflow-packages
setup-autocomplete
start-airflow
stop
restart
toggle-suppress-cheatsheet
toggle-suppress-asciiart"
_breeze_extra_arg_commands="
docker-compose
kind-cluster
prepare-provider-documentation
prepare-provider-packages
static-check
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}
;;
static-check)
_breeze_known_values=${_breeze_allowed_static_checks}
;;
-A | --install-airflow-version)
_breeze_known_values=${_breeze_allowed_install_airflow_versions}
;;
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}
;;
-D | --dockerhub-user)
_breeze_known_values="${_breeze_default_dockerhub_user}"
;;
-R | --dockerhub-repo)
_breeze_known_values="${_breeze_default_dockerhub_repo}"
;;
-g | --github-repository)
_breeze_known_values="${_breeze_default_github_repository}"
;;
-s | --github-image-id)
_breeze_known_values="${_breeze_default_github_image_id}"
;;
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}"
;;
--package-format)
_breeze_known_values="${_breeze_allowed_package_formats}"
;;
--installation-method)
_breeze_known_values="${_breeze_allowed_installation_methods}"
;;
--github-registry)
_breeze_known_values="${_breeze_allowed_github_registrys}"
;;
--generate-constraints-mode)
_breeze_known_values="${_breeze_allowed_generate_constraints_modes}"
;;
*)
_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
complete -F breeze_complete::_comp_breeze ./breeze