#!/bin/bash

SITE_LIB=$(python -c "import moduleframework, os; print os.path.dirname(moduleframework.__file__)")
MTF_TOOLS="tools"
JSON_LOG=$(mktemp)
AVOCADO_ARGS="--json $JSON_LOG"

function print_help {
  cat <<EOF
usage: mtf [-h|--help] [-l|--linters] [AVOCADO_ARGS]

positional arguments:
  AVOCADO_ARGS        test files and any arguments that "avocado run" accepts

optional arguments:
  -h, --help          show this help message and exit
  -l, --linters       also run default linter tests included in MTF
EOF
}

while [[ $# -gt 0 ]]; do
  case $1 in
      -h|--help)
        print_help
        exit 0
      ;;
      -l|--linters)
        AVOCADO_ARGS="$AVOCADO_ARGS $SITE_LIB/$MTF_TOOLS/*.py"
      ;;
      *)
        AVOCADO_ARGS="$AVOCADO_ARGS $1"
      ;;
  esac
  shift
done

avocado run $AVOCADO_ARGS
mtf-log-parser $JSON_LOG
rm -f $JSON_LOG
