#!/usr/bin/env bash
#MISE description="Import local fixture data, run the TUI, and clean tests/data/.task on exit"
#USAGE about "Import local fixture data, run the TUI, and clean tests/data/.task on exit"
#USAGE flag "--release" help="Run the TUI with cargo's release profile"
#MISE depends=["taskwarrior-tui:import-taskdata"]
#MISE depends_post=["taskwarrior-tui:clean-taskdata"]
#MISE interactive=true
set -euo pipefail

if [ -n "${usage_release:-}" ]; then
    set --
    if [ "$usage_release" = "true" ]; then
        set -- --release
    fi
else
    if [ "$#" -gt 1 ]; then
        echo "usage: run-taskdata [--release]" >&2
        exit 2
    fi

    if [ "$#" -eq 1 ] && [ "$1" != "--release" ]; then
        echo "usage: run-taskdata [--release]" >&2
        exit 2
    fi
fi

cleanup() {
    local status=$?
    set +e
    mise run taskwarrior-tui:clean-taskdata
    exit "$status"
}

trap cleanup EXIT

cargo run "$@"
