# shellcheck shell=dash

___x_cmd_hub_file_which_(){
    local remotefp="$1"; [ -n "$remotefp" ] || M='Provide resource path' N=hub log:ret:64
    remotefp="$(___x_cmd_hub_file_normalize_remotefp "$remotefp")"

    local cache_path=; cache_path="$(___x_cmd_hub_u_remote2localfp data "$remotefp")" || return 1
    if [ -z "$NO_CACHE" ] && [ -f "$cache_path" ] && ___x_cmd fileage --in 1h "$cache_path" ; then
        x_="$cache_path"
        return
    fi

    ___x_cmd_hub_file_cat "$remotefp" > "${cache_path}" || {
        [ ! -f "$cache_path" ] ||  ___x_cmd rm -f "$cache_path"
        return 1
    }
    x_="$cache_path"
}

___x_cmd_hub_file_which(){
    local X_help_cmd='___x_cmd_hub___help file which'
    help:arg-null:parse

    local NO_CACHE="${NO_CACHE}"
    case "$1" in
        --no-cache)      NO_CACHE=true; shift ;;
    esac

    local x_ ; ___x_cmd_hub_file_which_ "$1" || return 1
    printf "%s\n" "$x_"
}
