#!/bin/sh
# shellcheck shell=dash

set -u

APP_NAME="altertable"
DOWNLOAD_URL="https://github.com/altertable-ai/altertable-lakehouse-cli/releases/latest/download/altertable"
INSTALL_DIR="$HOME/.local/bin"

echo "Installing Altertable CLI..."
mkdir -p "$INSTALL_DIR"

if ! output="$(curl -LsSf "$DOWNLOAD_URL" -o "$INSTALL_DIR/$APP_NAME" 2>&1)"; then
  echo "❌ Failed to download $APP_NAME"
  echo "$output"
  exit 1
fi

chmod +x "$INSTALL_DIR/$APP_NAME"

echo "\n🎉 Altertable CLI installed successfully!"
echo "\nTo use it, add this directory to your PATH: \`export PATH=\"$INSTALL_DIR:\$PATH\"\`"
echo "\nNext steps:"
echo "1️⃣  Run \`altertable --help\` to see available commands."
printf "\nNeed help? See https://altertable.ai/docs\n"
