# shellcheck shell=dash

xrc:mod:lib     skill0   ls

___x_cmd_skill0___main(){
    [ "$#" -gt 0 ] ||   set -- --help

    local op="$1";      shift
    case "$op" in
        -h|--help)      ___x_cmd help -m skill0 "$@" ;  return 0 ;;

        which|which_|ls)
                        ___x_cmd_skill0_"$op"   "$@" ;;

        *)              N=skill0 M="Unknown subcmd -> $op" log:ret:64 ;;
    esac
}


___x_cmd_skill0_which(){
    [ $# -gt 0 ]    ||  N=skill0 M="Expect at least one argument." log:ret:64
    case "$1" in
        -h|--help)      ___x_cmd help -m skill0 which "$@" ; return 0 ;;
        "")             N=skill0 M="Expect a non-empty skill name " log:ret:64
    esac

    local x_=""
    ___x_cmd_skill0_which_ "$1" || return $?
    printf "%s\n" "$x_"
}

___x_cmd_skill0_which_(){
    local name="$1"

    case "$name" in
        */*)
            x_="${___X_CMD_ROOT_SKILL0}/$name"
            [ -e "${x_}/SKILL.md" ] || {
                x_=""; return 1
            }
            return 0
            ;;
    esac

    ___x_cmd fsiter --glob_ "$___X_CMD_ROOT_SKILL0" '*/*/SKILL.md' || return 1

    while read -r x_; do
        case "$x_" in
            */"$name/SKILL.md")     return 0    ;;
        esac
    done <<A
$x_
A

    x_=""
    return 1
}
