#!/usr/bin/env bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
source "$PLUGIN_AVAILABLE_PATH/config/functions"
source "$PLUGIN_AVAILABLE_PATH/ps/functions"

ps_restore_cmd() {
  declare desc="starts all apps with DOKKU_APP_RESTORE not set to 0 via command line"
  local cmd="ps:restore"
  for app in $(dokku_apps); do
    local DOKKU_APP_RESTORE=$(config_get "$app" DOKKU_APP_RESTORE || true)
    if [[ $DOKKU_APP_RESTORE != 0 ]]; then
      echo "Restoring app $app ..."
      ps_start "$app"
    fi
  done
}

ps_restore_cmd "$@"
