#!/usr/bin/bash
#shellcheck disable=SC1090

. "$(sfpath)" || exit 3

shellfu import pretty

shellfu import jats

usage() {
    mkusage "$@" "[options] BODY" \
        -- \
            "Discover test in suite located at PATH"                         \
        -o                                                                   \
            "-f FMT     Print test name in format FMT. 'id', 'version' or"   \
            "           'path'."                                             \
        --                                                                   \
            "Test body should consist of asserts and/or phases documented"   \
            "in jat.sh Shellfu module; use \`sfdoc jat\` to access its"    \
            "documentation."
}

main() {
    local finddirs=()
    local fmt=path
    while true; do case $1 in
        -f) fmt=$2; shift 2 || usage -w "missing FMT" ;;
        -*) usage -w "unknown argument: $1" ;;
        *)  break ;;
    esac done
    finddirs=("$@")
    case $fmt in
        id|path|version|ALL) : ;;
        *) usage -w "unknown FMT: $fmt" ;;
    esac
    debug -v finddirs fmt
    jats__sdiscover -f "$fmt" -- "${finddirs[@]}"
}

main "$@"
