#!/usr/bin/env bash
set -euo pipefail

usage() {
  echo "Usage: $0 [--file <tar_path>]" >&2
}

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
DEFAULT_INPUT="$PROJECT_ROOT/images/argus-master-dev.tar"
IMAGE_TAR="$DEFAULT_INPUT"

while [[ "$#" -gt 0 ]]; do
  case "$1" in
    --file)
      [[ $# -ge 2 ]] || { usage; exit 1; }
      IMAGE_TAR="$2"
      shift 2
      ;;
    -h|--help)
      usage
      exit 0
      ;;
    *)
      echo "Unknown option: $1" >&2
      usage
      exit 1
      ;;
  esac
 done

if [[ ! -f "$IMAGE_TAR" ]]; then
  echo "[ERROR] Image tarball not found: $IMAGE_TAR" >&2
  exit 1
fi

echo "[INFO] Loading image from $IMAGE_TAR"
docker image load -i "$IMAGE_TAR"
echo "[OK] Image loaded"
