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

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
RUNTIME="${CLOSEDBIT_RUNTIME:-$SCRIPT_DIR/closedbit-runtime-linux}"

if [ "$#" -gt 0 ]; then
  case "${1,,}" in
    *.cba)
      exec "$RUNTIME" "$@"
      ;;
    *.cbp)
      exec "$SCRIPT_DIR/cbpc-linux" check "$1"
      ;;
    *.cb|*.cbl)
      echo "ClosedBit Linux beta can inspect .cb/.cbl files from the compiler, but GUI editing is not shipped in this beta."
      exit 0
      ;;
  esac
fi

cat <<'TXT'
ClosedBit Linux Beta

Commands:
  closedbit app.cba
  cbpc-linux help
  cbpc-linux check source.cbp
  cbpc-linux compile cba source.cbp bin/app.cba
  cbpc-linux compile linux source.cbp bin/app-linux

The Linux beta uses the Linux package runner.
TXT
