#!/usr/bin/env bash

# Automatically generated by nengo-bones, do not edit this file directly

NAME=$0
COMMAND=$1
STATUS=0  # used to exit with non-zero status if any command fails

exe() {
    echo "\$ $*";
    # remove empty spaces from args
    args=( "$@" )
    for i in "${!args[@]}"; do
      [ -n "${args[$i]}" ] || unset "args[$i]"
    done
    "${args[@]}" || { echo -e "\033[1;31mCOMMAND '${args[0]}' FAILED\033[0m"; STATUS=1; }
}

if [[ ! -e nengo_spa ]]; then
    echo "Run this script from the root directory of this repository"
    exit 1
fi

if [[ "$COMMAND" == "install" ]]; then
    exe pip install "$NUMPY" "$SCIPY"

    exe pip install "pytest>=3.6.0"
    exe pip install "pytest-xdist>=1.16.0"
    exe pip install -e ".[tests]"
elif [[ "$COMMAND" == "before_script" ]]; then
    :
elif [[ "$COMMAND" == "script" ]]; then

    # shellcheck disable=SC2086
    exe pytest nengo_spa -v -n 2 --color=yes --durations 20 $TEST_ARGS


elif [[ "$COMMAND" == "before_cache" ]]; then
    :
elif [[ "$COMMAND" == "after_success" ]]; then
    :
elif [[ "$COMMAND" == "after_failure" ]]; then
    :
elif [[ "$COMMAND" == "before_deploy" ]]; then
    :
elif [[ "$COMMAND" == "after_deploy" ]]; then
    :
elif [[ "$COMMAND" == "after_script" ]]; then
    :
elif [[ -z "$COMMAND" ]]; then
    echo "$NAME requires a command like 'install' or 'script'"
else
    echo "$NAME does not define $COMMAND"
fi

if [[ "$COMMAND" != "script" && -n "$TRAVIS" && "$STATUS" -ne "0" ]]; then
    travis_terminate "$STATUS"
fi
exit "$STATUS"
