Adds support for windows backslash

Change-Id: I5323d622516e5e8e263f74af69e1bb06e338aa37
This commit is contained in:
Nathan Buckner 2015-05-20 15:26:49 -05:00
parent 4c9231e2c9
commit fec4d92966
1 changed files with 28 additions and 44 deletions

View File

@ -1,60 +1,44 @@
_cafe_runner()
{
local cur configs packages options product
local cur options
COMPREPLY=()
#get current word
cur="${COMP_WORDS[COMP_CWORD]}"
#get current word. sed for windows backslash
cur=$(echo "${COMP_WORDS[COMP_CWORD]}"|sed 's/\\/\\\\/g')
#Consumer only exists in the parallel runner
python -c "from cafe.drivers.unittest.runner import Consumer" 2>/dev/null
#if status is == 0 then we are running parallel runner
status=$?
#if last call was successful (0 return status we have the parallel runner
if ((1 > $status)); then
# process list options
options='--help --dry-run --exit-on-error --list --data-directory --regex-list --file --parallel --result --result-directory --tags --verbose --workers'
#parallel runner
if [ $status -eq 0 ]; then
if [[ ${cur} == -* ]]; then
COMPREPLY=( $(compgen -W "${options}" -- ${cur}) )
COMPREPLY="${COMPREPLY} "
return 0
options='--help --dry-run --exit-on-error --list --data-directory --regex-list --file --parallel --result --result-directory --tags --verbose --workers'
elif [[ ${COMP_CWORD} < 2 ]]; then
options=$(python -c "from cafe.drivers.unittest.autocomplete import print_configs;print_configs()")
else
options=$(python -c "from cafe.drivers.unittest.autocomplete import print_imports;print_imports(\"${cur}\")")
fi
# process configs
if [[ ${COMP_CWORD} < 2 ]]; then
configs=`python -c "from cafe.drivers.unittest.autocomplete import print_configs;print_configs()"`
COMPREPLY=( $(compgen -W "${configs}" -- ${cur}) )
COMPREPLY="${COMPREPLY} "
return 0
fi
# process repos (this does not account for option params)
packages=`echo $cur | python -c "import sys;from cafe.drivers.unittest.autocomplete import print_imports;print_imports(sys.stdin.read())"`
COMPREPLY=( $(compgen -W "${packages}" -- ${cur}) )
return 0
else # the normal runner
options='--help --test-repo --verbose --fail-fast --supress-load-tests --packages --module-regex --module --method-regex --tags --result --result-directory --parallel --dry-run --data-directory --data --list'
else #normal runner
if [[ ${cur} == -* ]]; then
COMPREPLY=( $(compgen -W "${options}" -- ${cur}) )
COMPREPLY="${COMPREPLY} "
return 0
options='--help --test-repo --verbose --fail-fast --supress-load-tests --packages --module-regex --module --method-regex --tags --result --result-directory --parallel --dry-run --data-directory --data --list'
elif [[ ${COMP_CWORD} < 2 ]]; then
options=$(python -c "from cafe.drivers.unittest.autocomplete import print_products;print_products()")
else
options=$(python -c "from cafe.drivers.unittest.autocomplete import print_configs_by_product;print_configs_by_product(\"${COMP_WORDS[1]}\")")
fi
# process product completion
if [[ ${COMP_CWORD} < 2 ]]; then
products=`python -c "from cafe.drivers.unittest.autocomplete import print_products;print_products()"`
COMPREPLY=( $(compgen -W "${products}" -- ${cur}) )
COMPREPLY="${COMPREPLY} "
return 0
fi
# process configs by product
configs=`python -c "import sys;from cafe.drivers.unittest.autocomplete import print_configs_by_product;print_configs_by_product(\"${COMP_WORDS[1]}\")"`
COMPREPLY=( $(compgen -W "${configs}" -- ${cur}) )
COMPREPLY="${COMPREPLY} "
return 0
fi
#sed for windows backslash
options=$(echo $options|sed 's/\\/\\\\/g')
COMPREPLY=( $(compgen -W '${options}' -- ${cur}) )
if [[ ${cur} == -* || ${COMP_CWORD} < 2 ]]; then
COMPREPLY="${COMPREPLY} "
elif [ $status -ne 0 ]; then
COMPREPLY="${COMPREPLY} "
fi
return 0
}
complete -o nospace -F _cafe_runner cafe-runner