Tools: completion: add bash completion for autotest.py

This commit is contained in:
Pierre Kancir 2020-04-03 17:36:27 +02:00 committed by Andrew Tridgell
parent 62ec6540ec
commit 3262175f86
2 changed files with 56 additions and 0 deletions

View File

@ -0,0 +1,55 @@
#!/usr/bin/env bash
_ap_autotest() {
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD - 1]}"
case "$cur" in
-*)
# TODO: generate for waf help
opts="--help -h"
opts+=" -j"
opts+=" --skip"
opts+=" --list"
opts+=" --list-subtests"
opts+=" --viewerip"
opts+=" --map"
opts+=" --experimental"
opts+=" --timeout"
opts+=" --frame"
opts+=" --show-test-timings"
opts+=" --validate-parameters"
opts+=" --no-configure"
opts+=" --waf-configure-args"
opts+=" --no-clean"
opts+=" --debug"
opts+=" --speedup"
opts+=" --valgrind"
opts+=" --gdb"
opts+=" --gdbserver"
opts+=" --lldb"
opts+=" -B --breakpoint"
opts+=" --disable-breakpoints"
;;
*)
# get the calling program, remove anything after the space == all commands arguments
local caller
caller=$(echo $@ | sed 's/ .*//g')
opts=$($caller --list)
;;
# TODO: add completion for subtests and skip list
esac
# Prevent word reuse
lim=$((COMP_CWORD - 1))
for i in $(seq 0 $lim); do
if [[ $opts == *"${COMP_WORDS[i]}"* ]]; then
opts=${opts//${COMP_WORDS[i]}/}
opts=${opts//--${COMP_WORDS[i]}/}
fi
done
COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
}
complete -F _ap_autotest autotest.py

View File

@ -4,3 +4,4 @@ _AP_COMPLETION_DIR=$(builtin cd "`dirname "${BASH_SOURCE[0]}"`" > /dev/null && p
source "$_AP_COMPLETION_DIR/bash/_waf"
source "$_AP_COMPLETION_DIR/bash/_sim_vehicle"
source "$_AP_COMPLETION_DIR/bash/_ap_bin"
source "$_AP_COMPLETION_DIR/bash/_ap_autotest"