#!/usr/bin/env bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
source "$PLUGIN_CORE_AVAILABLE_PATH/storage/functions"
source "$PLUGIN_CORE_AVAILABLE_PATH/docker-options/functions"

storage_unmount_cmd() {
  declare desc="Remove bind-mount, restart app if running"
  local cmd="storage:unmount"
  local passed_phases=(build deploy run)
  [[ -z $3 || $4 ]] && dokku_log_fail "storage:unmount requires an app and a two paths divided by colon."
  verify_app_name "$2" && local APP="$2"
  verify_paths "$3" && local MOUNT_PATH="$3"
  check_if_path_exists "$MOUNT_PATH" "$(get_phase_file_path "${passed_phases[@]}")" || dokku_log_fail "Mount path does not exist."
  remove_passed_docker_option passed_phases[@] "-v $MOUNT_PATH"
}

storage_unmount_cmd "$@"
