fix the spelling in whole piglit
[piglit.git] / completions / bash / piglit
blob87aeb9c95086f35c50aa4beeaaa1a22ac896de5b
1 #!/bin/bash
3 # Bash completions for piglit
4 # Copyright © 2016 Intel Corporation
6 # Permission is hereby granted, free of charge, to any person obtaining
7 # a copy of this software and associated documentation files (the "Software"),
8 # to deal in the Software without restriction, including without limitation
9 # the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 # and/or sell copies of the Software, and to permit persons to whom the
11 # Software is furnished to do so, subject to the following conditions:
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18 # OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20 # DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21 # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
22 # OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 # This provides completions for piglit in bash
26 # It requires debian's bash_completions (which are available on most
27 # linux and BSD OSes) for it's _filedir function.
29 __piglit_results_extensions="@(json|json.xz|json.gz|json.bz2)"
31 # Function that handles 'piglit run'
33 # This is a *very* complex function. It handles *most*, but not all of the
34 # functionality of 'piglit run'.
36 # This handles everything piglit run expects, with one small caveat, after the
37 # first profile is provided, it mixes profiles and directories together, since
38 # either additional profiles or a directory can be provided. After something
39 # that isn't a profile is provided it won't auto complete any more positional
40 # arguments.
41 __piglit_run() {
42 local cur=${COMP_WORDS[COMP_CWORD]}
43 local prev=${COMP_WORDS[COMP_CWORD-1]}
44 local opts="-h --help -f --config -n --name -d --dry-run \
45 -t --include-tests -x --exclude-tests -b \
46 --backend -c --all-concurrent -1 \
47 --no-concurrency -p --platform --valgrind \
48 --dmesg -s --sync --junit_suffix -l \
49 --log-level --test-list -p --platform"
50 local with_args=("-f" "--config" "-b" "--backend" "--junit_suffix"
51 "-l" "--log-level" "--test-list" "-n" "--name"
52 "-p" "--platform")
53 local profiles=("all" "cl" "cpu" "cts_gl" "cts_gl45" "cts_gles" "deqp_egl"
54 "deqp_gles2" "deqp_gles3" "deqp_gles31" "deqp_vk"
55 "glslparser" "gpu" "igt" "khr_gl" "khr_gl45"
56 "llvmpipe" "no_error" "oglconform" "quick" "quick_cl"
57 "sanity" "shader" "xts" "xts-render")
59 # If the argument begins with - then just show the -* options
60 if [[ "$cur" == -* ]]; then
61 COMPREPLY=( $(compgen -W "${opts}" -- $cur) )
62 return 0
65 case "$prev" in
66 "-f" | "--config")
67 _filedir '@(conf)'
68 return 0
70 "-b" | "--backend")
71 COMPREPLY=( $(compgen -W "json junit" -- $cur) )
72 return 0
74 "-l" | "--loglevel")
75 COMPREPLY=( $(compgen -W "quiet verbose dummy http" -- $cur) )
76 return 0
78 "--test-list")
79 _filedir
80 return 0
82 "-p" | "--platform")
83 COMPREPLY=( $(compgen -W "glx x11_egl wayland gbm mixed_glx_egl" -- $cur) )
84 return 0
86 "-n" | "--name" | "--junit_suffix")
87 return 0
89 esac
92 # Find any positional arguments.
93 # Positional arguments are arguments that don't start with - and that don't
94 # follow an argument that requires a positional argument
95 local list=( "${COMP_WORDS[@]:2}" ) # remove "piglit run"
96 local positional=0
97 if [[ ${#list[@]} -gt 0 ]]; then
98 for i in "${!list[@]}"; do
99 # If the element is an option argument continue
100 [[ ${list[$i]} == -* ]] && continue
102 # If the previous argument takes a positional argument continue
103 if [[ $i != 0 ]] && [[ "${with_args[@]}" =~ " ${list[$i-1]} " ]]; then
104 continue
107 # The spaces around list are significant, they prevent partial matches
108 if [[ ${positional} -eq 0 ]] && [[ "${list[$i]}" != "" ]]; then
109 [[ "${profiles[@]}" =~ "${list[$i]}" ]] && ((++positional))
111 # If the element is not a profile, and it is a complete file or directory
112 # then stop, there are no more positional arguments allowed, only switches
113 elif [[ ! "${profiles[@]}" =~ "${list[$i]}" ]]; then
114 [[ -a "${list[$i]}" ]] && [[ "${list[$i+1]}" == '' ]] && return 0
116 # Bash and whitespace...
117 elif [[ "${list[$i]}" != "" ]]; then
118 ((++positional))
120 done
123 # 'piglit run' has two positional arguments
124 # TODO: more than one profile can be specified. but how?
125 # 1) The profile to run
126 # 2) the location to save the file to
127 COMPREPLY=( $(compgen -W "${profiles[*]}" -- $cur) )
128 case "$positional" in
129 '0')
130 return 0
133 _filedir -d
134 return 0
136 esac
139 # Handle 'piglit resume'
141 # Resume is very simple, it takes only a couple of options, and a single
142 # positional argument.
143 __piglit_resume() {
144 local cur=${COMP_WORDS[COMP_CWORD]}
145 local prev=${COMP_WORDS[COMP_CWORD-1]}
146 local with_args=("-f" "--config")
148 if [[ "$cur" == -* ]]; then
149 COMPREPLY=( $(compgen -W "-f --config -n --no-retry -h --help" -- $cur) )
150 return 0
153 if [[ "$prev" == "-f" ]] || [[ "$prev" == "--config" ]]; then
154 _filedir -d
155 return 0
158 local count=0
159 for _ in "${COMP_WORDS[@]:3}"; do # remove 'piglit resume'
160 if [[ ! "$with_args" =~ " $prev" ]]; then
161 ((++count))
163 done
165 if [[ $count -eq 0 ]]; then
166 _filedir -d
167 return 0
169 return 1
172 # Handle 'piglit summary aggregate'
174 # This is a very simple function, it takes only one positional argument, and only
175 # a single positional argument
176 __piglit_summary_aggregate() {
177 local cur=${COMP_WORDS[COMP_CWORD]}
178 local prev=${COMP_WORDS[COMP_CWORD-1]}
179 local with_args=("-f" "--config" "-o" "--output")
181 if [[ "$cur" == -* ]]; then
182 COMPREPLY=( $(compgen -W "-f --config -o --output --help" -- $cur) )
183 return 0
186 case $prev in
187 "-f" | "--config")
188 _filedir -d
189 return 0
191 "-o" | "--output")
192 _filedir "${__piglit_results_extensions}"
193 return 0
195 esac
197 local count=0
198 for _ in "${COMP_WORDS[@]:4}"; do # remove 'piglit resume'
199 if [[ ! "$with_args" =~ "$prev" ]]; then
200 ((++count))
202 done
204 if [[ $count -eq 0 ]]; then
205 _filedir -d
206 return 0
208 return 1
211 # Completions for 'summary console'
213 # This function is extremely simple, it takes an infinite number of positional
214 # arguments which are all the same, a couple of switches, and only two of them
215 # take arguments.
216 __piglit_summary_console() {
217 local cur=${COMP_WORDS[COMP_CWORD]}
218 local prev=${COMP_WORDS[COMP_CWORD-1]}
219 local opts="-h --help -f --config -d --dif -s --summary -i --incomplete \
220 -l --list"
222 if [[ "$cur" == -* ]]; then
223 COMPREPLY=( $(compgen -W "${opts}" -- $cur) )
224 return 0
227 case "$prev" in
228 "-f" | "--config")
229 _filedir
230 return 0
232 "-l" | "--list")
233 _filedir
234 return 0
236 esac
238 _filedir "${__piglit_results_extensions}"
239 return 0
242 # Completions for 'summary csv'
244 # This is super simple, it has basically no switches, and the one positional
245 # argument can be provided multiple times
246 __piglit_summary_csv() {
247 local cur=${COMP_WORDS[COMP_CWORD]}
248 local prev=${COMP_WORDS[COMP_CWORD-1]}
249 local opts="-h --help -f --config -o --output"
251 if [[ "$cur" == -* ]]; then
252 COMPREPLY=( $(compgen -W "${opts}" -- $cur) )
253 return 0
256 case "$prev" in
257 "-f" | "--config")
258 _filedir
259 return 0
261 "-o" | "--output")
262 _filedir "@(csv)"
263 return 0
265 esac
267 _filedir "${__piglit_results_extensions}"
268 return 0
272 # Completions for 'piglit summary feature'
274 # This is a very simple file. It takes 3 positional arguments, the last can be
275 # repeated as many times as desired, and two simple switches.
276 __piglit_summary_feature() {
277 local cur=${COMP_WORDS[COMP_CWORD]}
278 local prev=${COMP_WORDS[COMP_CWORD-1]}
279 local opts="-h --help -o --overwrite"
281 if [[ "$cur" == -* ]]; then
282 COMPREPLY=( $(compgen -W "${opts}" -- $cur) )
283 return 0
286 local list=( "${COMP_WORDS[@]:3}" ) # remove "piglit run"
287 local positional=0
288 if [[ ${#list[@]} -gt 0 ]]; then
289 for i in "${!list[@]}"; do
290 # If the element is an option argument continue
291 [[ ${list[$i]} == '-*' ]] && continue
293 # Bash and whitespace...
294 [[ "${list[$i]}" != "" ]] && ((++positional))
295 done
298 case "${positional}" in
299 '0')
300 _filedir '@(json)'
301 return 0
303 '1')
304 _filedir -d
305 return 0
308 _filedir "${__piglit_results_extensions}"
309 return 0
311 esac
314 # Completions for 'piglit summary html'
316 # This is another fairly complex function to complete. It provides two
317 # different positional arguments, the first can be specified only once, the
318 # second can be provided an infinite number of times. It also provides a few
319 # switches that have positional arguments.
320 __piglit_summary_html() {
321 local cur=${COMP_WORDS[COMP_CWORD]}
322 local prev=${COMP_WORDS[COMP_CWORD-1]}
323 local opts="-h --help -o --overwrite -f --config -l --list \
324 -e --exclude-details"
325 local with_args=("-f" "--config" "-e" "--exclude")
327 if [[ "$cur" == -* ]]; then
328 COMPREPLY=( $(compgen -W "${opts}" -- $cur) )
329 return 0
332 case "$prev" in
333 "-f" | "--config")
334 _filedir '@(conf)'
335 return 0
337 "-e" | "--exclude-details")
338 local exclude="all crash timeout incomplete \
339 pass dmesg-warn dmesg-fail \
340 notrun fail warn skip"
341 COMPREPLY=( $(compgen -W "${exclude}" -- $cur) )
342 return 0
344 esac
346 local list=( "${COMP_WORDS[@]:3}" ) # remove "piglit run"
347 local positional=0
348 if [[ ${#list[@]} -gt 0 ]]; then
349 for i in "${!list[@]}"; do
350 # If the element is an option argument continue
351 [[ ${list[$i]} == '-*' ]] && continue
353 # If the previous argument takes a positional argument continue
354 if [[ $i != 0 ]] && [[ "${with_args[@]}" =~ "${list[$i-1]}" ]]; then
355 continue
358 # Bash and whitespace...
359 [[ "${list[$i]}" != "" ]] && ((++positional))
360 done
363 case "$positional" in
364 "0")
365 _filedir -d
366 return 0
369 _filedir "${__piglit_results_extensions}"
370 return 0
372 esac
375 # Completions for 'piglit'
377 # This function provides the completions for piglit, and calls subparsers for
378 # 'piglit run' and 'piglit resume', while it handles 'piglit summary' itself,
379 # delegating subparsers for the sub commands of 'piglit summary'
380 _piglit() {
381 local cur=${COMP_WORDS[COMP_CWORD]}
382 local sub=${COMP_WORDS[1]}
384 case "$sub" in
385 "run")
386 __piglit_run
387 return 0
389 "resume")
390 __piglit_resume
391 return 0
393 "summary")
394 case "${COMP_WORDS[2]}" in
395 "aggregate")
396 __piglit_summary_aggregate
397 return 0
399 "console")
400 __piglit_summary_console
401 return 0
403 "csv")
404 __piglit_summary_csv
405 return 0
407 "feature")
408 __piglit_summary_feature
409 return 0
411 "html")
412 __piglit_summary_html
413 return 0
416 if [[ $COMP_CWORD -gt 2 ]]; then
417 return 1
420 COMPREPLY=( $(compgen -W "html console csv aggregate feature" -- "${cur}") )
421 return 0
423 esac
426 if [[ $COMP_CWORD -gt 1 ]]; then
427 return 1
430 COMPREPLY=( $(compgen -W "run summary resume" -- $cur) )
431 return 0
433 esac
436 complete -F _piglit piglit