forked from buildtesters/buildtest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbash_completion.sh
317 lines (278 loc) · 11 KB
/
bash_completion.sh
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
# This is the bash completion script for buildtest
# For auto completion via compgen, options are sorted alphabetically in the format: <longoption> <shortoption> <subcommands>
# For more details see https://www.gnu.org/software/bash/manual/html_node/Programmable-Completion-Builtins.html
if test -n "${ZSH_VERSION:-}" ; then
if [[ "$(emulate)" = zsh ]] ; then
if ! typeset -f compdef >& /dev/null ; then
# See https://zsh.sourceforge.io/Doc/Release/Completion-System.html##Use-of-compinit
# ensure base completion support is enabled, ignore insecure directories
autoload -U +X compinit && compinit -i
fi
if ! typeset -f complete >& /dev/null ; then
# ensure bash compatible completion support is enabled. See https://stackoverflow.com/questions/3249432/can-a-bash-tab-completion-script-be-used-in-zsh
autoload -U +X bashcompinit && bashcompinit
fi
emulate sh -c "source '$0:A'"
return # stop interpreting file
fi
fi
# get list of available tags
_avail_tags ()
{
buildtest buildspec find --tags --terse --no-header 2>/dev/null
}
# get list of buildspecs in cache
_avail_buildspecs ()
{
buildtest buildspec find --buildspec --terse --no-header 2>/dev/null
}
# get list of schemas
_avail_schemas ()
{
buildtest schema
}
# list of available executors
_avail_executors ()
{
buildtest config executors
}
# list of test ids from report
_test_ids ()
{
buildtest inspect list -t -n | cut -d '|' -f 1
}
# list of test names from report
_test_name ()
{
buildtest inspect list -t -n | cut -d '|' -f 2 | uniq | sort
}
_builder_names()
{
buildtest inspect list -b
}
# list of buildspecs from report
_test_buildspec ()
{
buildtest inspect list -t -n | cut -d '|' -f 3 | uniq | sort
}
# list of history id
_history_id ()
{
buildtest history list -t -n | cut -d '|' -f 1 | sort -g
}
_buildspec_cache_test_names()
{
buildtest buildspec find --format name --terse -n | sort
}
# entry point to buildtest bash completion function
_buildtest ()
{
local cur="${COMP_WORDS[COMP_CWORD]}"
local prev="${COMP_WORDS[COMP_CWORD-1]}"
COMPREPLY=() # Array variable storing the possible completions.
local cmds="build buildspec cd cdash clean config debugreport docs edit help inspect history path report schema schemadocs stylecheck unittests"
local alias_cmds="bd bc cg it et h hy rt style"
local opts="--color --config --debug --help --lastlog --report --version -c -d -h -r -V"
next=${COMP_WORDS[1]}
case "$next" in
build|bd)
local shortoption="-b -e -et -f -k -m -s -t -u -x"
local longoption="--buildspec --disable-executor-check --executor --executor-type --exclude --filter --helpfilter --maxpendtime --modules --module-purge --nodes --pollinterval --procs --rerun --retry --stage --tags --unload-modules"
local allopts="${longoption} ${shortoption}"
COMPREPLY=( $( compgen -W "$allopts" -- $cur ) )
# fill auto-completion for 'buildtest build --executor'
if [[ "${prev}" == "-e" ]] || [[ "${prev}" == "--executor" ]]; then
COMPREPLY=( $( compgen -W "$(_avail_executors)" -- $cur ) )
fi
# fill auto-completion for 'buildtest build --stage'
if [[ "${prev}" == "-s" ]] || [[ "${prev}" == "--stage" ]]; then
COMPREPLY=( $( compgen -W "stage parse" -- $cur ) )
fi
# fill auto-completion for 'buildtest build --executor-type'
if [[ "${prev}" == "-et" ]] || [[ "${prev}" == "--executor-type" ]]; then
COMPREPLY=( $( compgen -W "local batch" -- $cur ) )
fi
# fill auto-completion for 'buildtest build --tag'
if [[ "${prev}" == "-t" ]] || [[ "${prev}" == "--tag" ]]; then
COMPREPLY=( $( compgen -W "$(_avail_tags)" -- $cur ) )
fi
# fill auto-completion for 'buildtest build --buildspec'
if [[ "${prev}" == "-b" ]] || [[ "${prev}" == "--buildspec" ]] || [[ "${prev}" == "-x" ]] || [[ "${prev}" == "--exclude" ]] ; then
COMPREPLY=( $( compgen -W "$(_avail_buildspecs)" -- $cur ) )
fi
;;
cd)
COMPREPLY=( $( compgen -W "$(_builder_names)" -- $cur ) );;
clean)
local opts="-h --help -y --yes"
COMPREPLY=( $( compgen -W "$opts" -- $cur ) )
;;
path)
local opts="-b -e -h -o -s -t --buildscript --errfile --help --outfile --stagedir --testpath"
COMPREPLY=( $( compgen -W "$(_builder_names)" -- $cur ) )
if [[ $cur == -* ]] ; then
COMPREPLY=( $( compgen -W "$opts" -- $cur ) )
fi
;;
schema)
local opts="-h -n -e -j --name --example --json"
COMPREPLY=( $( compgen -W "$opts" -- $cur ) )
# fill auto-completion for 'buildtest schema --name'
if [[ "${prev}" == "-n" ]] || [[ "${prev}" == "--name" ]]; then
COMPREPLY=( $( compgen -W "$(_avail_schemas)" -- $cur ) )
fi
;;
report|rt)
local opts="--filter --format --help --helpfilter --helpformat --latest --no-header --oldest --pager --terse -h -n -t clear list summary"
COMPREPLY=( $( compgen -W "$opts" -- $cur ) )
case "${COMP_WORDS[2]}" in summary)
local opts="-h --help --pager"
COMPREPLY=( $( compgen -W "${opts}" -- $cur ) )
;;
esac
;;
config|cg)
local cmds="-h --help compilers edit executors validate view systems"
COMPREPLY=( $( compgen -W "${cmds}" -- $cur ) )
# handle completion logic for 'buildtest config <subcommand>' based on subcommands
case "${COMP_WORDS[2]}" in
compilers)
local opts="--help --json --yaml -h -j -y find"
COMPREPLY=( $( compgen -W "${opts}" -- $cur ) )
if [[ "${prev}" == "find" ]]; then
local opts="--debug --help --update -d -h -u"
COMPREPLY=( $( compgen -W "${opts}" -- $cur ) )
fi
;;
executors)
local opts="--help --disabled --invalid --json --yaml -d -h -i -j -y"
COMPREPLY=( $( compgen -W "${opts}" -- $cur ) );;
view|validate|summary|systems)
local opts="-h --help"
COMPREPLY=( $( compgen -W "${opts}" -- $cur ) );;
esac
;;
inspect|it)
local cmds="--help -h buildspec list name query"
COMPREPLY=( $( compgen -W "${cmds}" -- $cur ) )
# case statement to handle completion for buildtest inspect [name|id|list] command
case "${COMP_WORDS[2]}" in
list)
local opts="--builder --help --no-header --terse -b -h -n -t"
COMPREPLY=( $( compgen -W "${opts}" -- $cur ) );;
name)
COMPREPLY=( $( compgen -W "$(_builder_names)" -- $cur ) )
if [[ $cur == -* ]] ; then
local opts="--all --help -a -h"
COMPREPLY=( $( compgen -W "${opts}" -- $cur ) )
fi
;;
buildspec)
COMPREPLY=( $( compgen -W "$(_test_buildspec)" -- $cur ) )
if [[ $cur == -* ]] ; then
local opts="--all --help -a -h"
COMPREPLY=( $( compgen -W "${opts}" -- $cur ) )
fi
;;
query)
COMPREPLY=( $( compgen -W "$(_builder_names)" -- $cur ) )
if [[ $cur == -* ]] ; then
local opts="--buildscript --error --help --output --testpath -b -e -o -h -o -t"
COMPREPLY=( $( compgen -W "${opts}" -- $cur ) )
fi
;;
esac
;;
buildspec|bc)
local cmds="-h --help edit edit-file find show summary validate"
COMPREPLY=( $( compgen -W "${cmds}" -- $cur ) )
# switch based on 2nd word 'buildtest buildspec <subcommand>'
case ${COMP_WORDS[2]} in
find)
case ${COMP_WORDS[3]} in
# completion for 'buildtest buildspec find invalid'
invalid)
local opts="--error --help -e -h"
COMPREPLY=( $( compgen -W "${opts}" -- $cur ) );;
# completion for rest of arguments
*)
local longopts="--buildspec --executors --filter --format --group-by-executor --group-by-tags --help --helpfilter --helpformat --maintainers --maintainers-by-buildspecs --no-header --pager --paths --rebuild --tags --root --terse"
local shortopts="-b -e -h -m -mb -n -p -r -t"
local subcmds="invalid"
local allopts="${longopts} ${shortopts} ${subcmds}"
COMPREPLY=( $( compgen -W "${allopts}" -- $cur ) );;
esac
;;
show|edit)
COMPREPLY=( $( compgen -W "$(_buildspec_cache_test_names)" -- $cur ) );;
edit-file)
COMPREPLY=( $( compgen -W "$(_avail_buildspecs)" -- $cur ) );;
validate)
local opts="--buildspec --exclude --executor --tag -b -e -t -x "
COMPREPLY=( $( compgen -W "${opts}" -- $cur ) )
# auto completion for 'buildtest buildspec validate' options
if [[ "${prev}" == "-b" ]] || [[ "${prev}" == "--buildspec" ]] || [[ "${prev}" == "-x" ]] || [[ "${prev}" == "--exclude" ]]; then
COMPREPLY=( $( compgen -W "$(_avail_buildspecs)" -- $cur ) )
elif [[ "${prev}" == "-t" ]] || [[ "${prev}" == "--tags" ]]; then
COMPREPLY=( $( compgen -W "$(_avail_tags)" -- $cur ) )
elif [[ "${prev}" == "-e" ]] || [[ "${prev}" == "--executor" ]]; then
COMPREPLY=( $( compgen -W "$(_avail_executors)" -- $cur ) )
fi
;;
esac
;;
history|hy)
local cmds="--help -h list query"
COMPREPLY=( $( compgen -W "${cmds}" -- $cur ) )
case ${COMP_WORDS[2]} in
list)
local opts="--help --no-header --pager --terse -h -n -t"
COMPREPLY=( $( compgen -W "${opts}" -- $cur ) );;
query)
local opts="--help --log --output -h -l -o"
COMPREPLY=( $( compgen -W "$(_history_id)" -- $cur ) )
if [[ $cur == -* ]]; then
COMPREPLY=( $( compgen -W "${opts}" -- $cur ) )
fi
;;
esac
;;
cdash)
local cmds="--help -h upload view"
COMPREPLY=( $( compgen -W "${cmds}" -- $cur ) )
if [[ "${prev}" == "view" ]]; then
local opts="-h --help"
COMPREPLY=( $( compgen -W "${opts}" -- $cur ) )
elif [[ "${prev}" == "upload" ]]; then
local opts="-h --help --site"
COMPREPLY=( $( compgen -W "${opts}" -- $cur ) )
fi
;;
stylecheck|style)
local opts="--help --no-black --no-isort --no-pyflakes --apply -a -h"
COMPREPLY=( $( compgen -W "${opts}" -- $cur ) )
;;
unittests)
local opts="--coverage --help --pytestopts --sourcefiles -c -h -p -s"
COMPREPLY=( $( compgen -W "${opts}" -- $cur ) )
;;
help|h)
local cmds="build buildspec cdash config history inspect path report schema stylecheck unittests"
COMPREPLY=( $( compgen -W "${cmds}" -- $cur ) )
;;
*)
case "${cur}" in
# print main options to buildtest
-*)
COMPREPLY=( $( compgen -W "${opts}" -- $cur ) );;
# print main sub-commands to buildtest
*)
COMPREPLY=( $( compgen -W "${cmds} ${alias_cmds}" -- $cur ) )
if [[ "${prev}" == "--color" ]]; then
COMPREPLY=( $( compgen -W "on off" -- $cur ) )
fi
;;
esac
esac
}
complete -o default -F _buildtest buildtest