#!/usr/bin/env bash
# Command-line entry point for the Canvas archive.
#
#   vt canvas courses                every enrolment, concluded included; writes nothing
#   vt canvas plan                   item counts and bytes per course; downloads nothing
#   vt canvas pull --course 123456   archive one course into the vault
#   vt move OLD NEW                  move a note or folder and rewrite inbound links
set -euo pipefail

cd "$(dirname "$0")/.."

# `vt canvas extract` needs third-party parsers (requirements.txt), so prefer
# the package's virtualenv when there is one.
if [ -x ".venv/bin/python" ]; then
    PYTHON=".venv/bin/python"
else
    PYTHON="$(command -v python3)"
fi

case "${1:-}" in
    canvas)    shift; exec "$PYTHON" -m tools.canvas "$@" ;;
    move)      shift; exec "$PYTHON" -m tools.move "$@" ;;
    "")        echo "usage: vt {canvas|move} [args...]" >&2; exit 2 ;;
    *)         echo "vt: unknown tool '$1' (expected: canvas, move)" >&2; exit 2 ;;
esac
