#!/usr/bin/env bash
# playable — run rust-lang/rustlings locally
# https://0.0.0.0:3000/rust-lang/rustlings
set -euo pipefail

bold() { printf "\033[1m%s\033[0m\n" "$*"; }
need() { command -v "$1" >/dev/null 2>&1 || { echo "missing: $1 — install it and re-run"; exit 1; }; }

need git
need cargo

WORKDIR="${PLAYABLE_DIR:-$HOME/.playable/rust-lang}"
mkdir -p "$WORKDIR"
cd "$WORKDIR"
if [ -d "rustlings/.git" ]; then
  bold "Updating rust-lang/rustlings…"; git -C "rustlings" pull --ff-only || true
else
  bold "Cloning rust-lang/rustlings…"; git clone --depth 1 "https://github.com/rust-lang/rustlings.git" "rustlings"
fi
cd "rustlings"


bold "Running: cargo run"
cargo run
