#!/usr/bin/env bash
# Stop the whole stack, or the named services only (data volumes are kept).
source "$(dirname "${BASH_SOURCE[0]}")/common.sh"
require_docker

has_service_args() {
  local arg
  for arg in "$@"; do
    case "${arg}" in
      -*) ;;
      *) return 0 ;;
    esac
  done
  return 1
}

# Only a full down owns the orphan sweep and the host-open helper: with an
# explicit service list every other service is meant to keep running.
if has_service_args "$@"; then
  dc down "$@"
else
  dc down --remove-orphans "$@"
  stop_host_open
fi
