forked from apache/airflow
-
Notifications
You must be signed in to change notification settings - Fork 6
/
breeze-complete
143 lines (126 loc) · 4.67 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
#!/usr/bin/env bash
_BREEZE_ALLOWED_PYTHON_VERSIONS=" 3.5 3.6 2.7 "
_BREEZE_ALLOWED_ENVS=" docker kubernetes "
_BREEZE_ALLOWED_BACKENDS=" sqlite mysql postgres "
_BREEZE_ALLOWED_KUBERNETES_VERSIONS=" v1.13.0 "
_BREEZE_ALLOWED_KUBERNETES_MODES=" persistent_mode git_mode "
_BREEZE_ALLOWED_STATIC_CHECKS=" all check-hooks-apply check-merge-conflict check-executables-have-shebangs check-xml detect-private-key doctoc end-of-file-fixer flake8 forbid-tabs insert-license check-apache-license lint-dockerfile mixed-line-ending mypy pylint shellcheck"
_BREEZE_DEFAULT_DOCKERHUB_USER="apache"
_BREEZE_DEFAULT_DOCKERHUB_REPO="airflow"
_BREEZE_SHORT_OPTIONS="
h P: E: B: K: M:
s b O
v y C A
r R p u
c D: H: e a
t: d: k x: S: F:
"
_BREEZE_LONG_OPTIONS="
help python: env: backend: kubernetes-version: kubernetes-mode:
skip-mounting-local-sources build-only build-docs
verbose assume-yes toggle-suppress-cheatsheet toggle-suppress-asciiart
force-rebuild-images force-rebuild-images-clean force-pull-images push-images
cleanup-images dockerhub-user: dockerhub-repo: initialize-local-virtualenv setup-autocomplete
test-target: docker-compose: stop-environment execute-command: static-check: static-check-all-files:
"
# Note on OSX bash has no associative arrays (Bash 3.2) so we have to fake it
_BREEZE_KNOWN_VALUES=""
function _get_known_values_breeze {
case "$1" in
-P | --python )
_BREEZE_KNOWN_VALUES=${_BREEZE_ALLOWED_PYTHON_VERSIONS} ;;
-E | --env )
_BREEZE_KNOWN_VALUES=${_BREEZE_ALLOWED_ENVS} ;;
-B | --backend )
_BREEZE_KNOWN_VALUES=${_BREEZE_ALLOWED_BACKENDS} ;;
-K | --kubernetes-version )
_BREEZE_KNOWN_VALUES=${_BREEZE_ALLOWED_KUBERNETES_VERSIONS} ;;
-M | --kubernetes-mode )
_BREEZE_KNOWN_VALUES=${_BREEZE_ALLOWED_KUBERNETES_MODES} ;;
-S | --static-check )
_BREEZE_KNOWN_VALUES=${_BREEZE_ALLOWED_STATIC_CHECKS} ;;
-F | --static-check-all-files )
_BREEZE_KNOWN_VALUES=${_BREEZE_ALLOWED_STATIC_CHECKS} ;;
-d | --docker-compose )
# shellcheck disable=SC2034
if typeset -f "_docker_compose" > /dev/null; then
_docker_compose
fi
_BREEZE_KNOWN_VALUES="" ;;
-D | --dockerhub-user )
_BREEZE_KNOWN_VALUES="${_BREEZE_DEFAULT_DOCKERHUB_USER}" ;;
-H | --dockerhub-repo )
_BREEZE_KNOWN_VALUES="${_BREEZE_DEFAULT_DOCKERHUB_REPO}" ;;
*)
_BREEZE_KNOWN_VALUES=""
esac
}
_BREEZE_GETOPT_SHORT_OPTIONS=""
_BREEZE_GETOPT_LONG_OPTIONS=""
function _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
}
function _listcontains_breeze {
local WORD
for WORD in $1; do
[[ ${WORD} = "$2" ]] && return 0
done
return 1
}
# A completion function for breeze
function _comp_breeze {
local ALL_OPTIONS=""
local EXTRA_ARG_OPTIONS=""
local OPTION
local GETOPT_OPTION
local LAST_COMMAND_PREFIX
local PREVIOUS_COMMAND
for OPTION in ${_BREEZE_SHORT_OPTIONS}
do
LAST_CHAR="${OPTION:$((${#OPTION}-1)):1}"
GETOPT_OPTION='-'${OPTION//:/}
if [[ "${LAST_CHAR}" == ":" ]]; then
EXTRA_ARG_OPTIONS="${EXTRA_ARG_OPTIONS} ${GETOPT_OPTION}"
fi
ALL_OPTIONS="${ALL_OPTIONS} ${GETOPT_OPTION}"
done
for OPTION in ${_BREEZE_LONG_OPTIONS}
do
LAST_CHAR="${OPTION:$((${#OPTION}-1)):1}"
GETOPT_OPTION='--'${OPTION//:/}
ALL_OPTIONS="${ALL_OPTIONS} ${GETOPT_OPTION}"
if [[ "${LAST_CHAR}" == ":" ]]; then
EXTRA_ARG_OPTIONS="${EXTRA_ARG_OPTIONS} ${GETOPT_OPTION}"
fi
done
LAST_COMMAND_PREFIX="${COMP_WORDS[${#COMP_WORDS[@]}-1]}"
if [[ ${#COMP_WORDS[@]} -gt 1 ]]; then
PREVIOUS_COMMAND="${COMP_WORDS[${#COMP_WORDS[@]}-2]}"
else
PREVIOUS_COMMAND=""
fi
if _listcontains_breeze "${EXTRA_ARG_OPTIONS}" "${PREVIOUS_COMMAND}"; then
COMPREPLY=()
_get_known_values_breeze "${PREVIOUS_COMMAND}"
while IFS='' read -r LINE; do COMPREPLY+=("$LINE"); done \
< <(compgen -W "${_BREEZE_KNOWN_VALUES}" -- "${LAST_COMMAND_PREFIX}")
else
COMPREPLY=()
while IFS='' read -r LINE; do COMPREPLY+=("$LINE"); done \
< <(compgen -W "${ALL_OPTIONS}" -- "${LAST_COMMAND_PREFIX}")
fi
}
_build_options_breeze
complete -F _comp_breeze breeze