#!/usr/bin/env bash

# Usage: script/parse-examples [native|wasm]

# Exit immediately if a command exits with a non-zero status.
set -e

# Parse examples in 'native' or 'wasm' mode.
mode=${1:-native}

# Change directory to project root.
cd "$(dirname "$0")/.."

# Clone a GitHub repository to the examples directory
# clone_repo OWNER NAME SHA
function clone_repo {
  owner=$1
  name=$2
  sha=$3

  path=examples/$name
  if [ ! -d "$path" ]; then
    git clone "https://github.com/$owner/$name" "$path" --quiet
  fi

  pushd "$path" >/dev/null
  git fetch --quiet
  git reset --hard $sha --quiet
  popd >/dev/null
}

clone_repo knausj85 knausj_talon 000015ed1bd4cb1109d7d6ddaaa4146821821d70
clone_repo AndreasArvidsson andreas-talon 9e467003d32da694b1fdf74ef97543c9b3d2d613
clone_repo phillco talon-axkit ea39bb16d037c3ddcd5acc1666f20b2f80b9a931

for name in knausj_talon andreas-talon talon-axkit; do
  script/parse-example "$name" "$mode"
done