#!/usr/bin/env bash
# Usage: ghe-cluster-each
# Emulates the remote GitHub ghe-cluster-each command. Tests use this
# to assert that the command was executed.
set -e

for _ in "$@"; do
  case "$1" in
    --)
      if [ "$1" = "--" ]; then
        shift
        COMMAND="$*"
      fi
      break
      ;;
  esac
done

if [ "$COMMAND" == "ghe-version" ]; then
  if [ -z "$DIFFERENT_VERSIONS" ]; then
    echo "fake-uuid: GitHub Enterprise Server 3.1.0 lxc 2020-12-16 5e97c07602"
    echo "fake-uuid1: GitHub Enterprise Server 3.1.0 lxc 2020-12-16 5e97c07602"
    echo "fake-uuid2: GitHub Enterprise Server 3.1.0 lxc 2020-12-16 5e97c07602"
  else
    echo "fake-uuid: GitHub Enterprise Server 3.1.0 lxc 2020-12-16 5e97c07602"
    echo "fake-uuid1: GitHub Enterprise Server 3.1.0 lxc 2020-12-16 5e97c07602"
    echo "fake-uuid2: GitHub Enterprise Server 2.19 lxc 2020-12-13 5e97c07622"
  fi
  exit 0
fi

if [ "$COMMAND" == "/usr/local/share/enterprise/ghe-nomad-cleanup" ]; then
  echo "nomad cleanup"
  exit 0
fi
