#!/usr/bin/env bash
# @conventions task runner. Invoke via the repo-root `run` symlink (-> scripts/cli/run).
#   ./run lint:yaml    validate all conventions against convention.yaml.schema
#   ./run help
set -euo pipefail

# Resolve repo root regardless of where `run` is invoked from or that it's a symlink.
self="${BASH_SOURCE[0]}"
self="$(python3 -c 'import os,sys; print(os.path.realpath(sys.argv[1]))' "$self")"
REPO="$(cd "$(dirname "$self")/../.." && pwd)"
cd "$REPO"

cmd="${1:-help}"
case "$cmd" in
  lint:yaml)
    exec python3 scripts/cli/lint_yaml.py
    ;;
  help | -h | --help)
    cat <<'EOF'
@conventions — task runner
  run lint:yaml   validate every programming_*/<name>.yaml against convention.yaml.schema
  run help        this message
EOF
    ;;
  *)
    echo "unknown command: $cmd" >&2
    echo "try: run help" >&2
    exit 2
    ;;
esac
