#!/bin/bash

container=$(docker-compose ps -q)
if [[ "${container}" == "" ]]; then
  >&2 echo "ketr.chat not running. Try './launch'"
  exit 1
fi

name=$(docker container ls -f id="${container}" --format "{{.Names}}")
if [[ "${name}" == "" ]]; then
  >&2 echo "No container name found for ${container}"
  exit 1
fi

command="${@}"
command="${command:-/opt/scripts/shell}"

if [[ "${name}" =~ -production ]]; then
  echo "Starting shell in PRODUCTION"
  docker exec -it "${name}" ${command}
else
  echo "Starting shell in DEVELOPMENT"
  docker exec -it "${name}" ${command}
fi
