# shellcheck shell=dash

___x_cmd_hub_file_rm(){
    local X_help_cmd='___x_cmd_hub___help file rm'
    help:arg:parse

    local recurse=false
    local force=false
    local cache
    while [ $# -gt 0 ] ; do
        case "$1" in
            --recurse|-r)   recurse=true;   shift ;;
            --force|-f)     force=true;     shift ;;
            --cache)        cache=true;     shift ;;
            *) break ;;
        esac
    done

    [ -z "$cache" ] || {
        local x_ ; ___x_cmd_hub_file_which_ "$1" || return 1
        if [ -f "$x_" ];then
            ___x_cmd rmrf "$x_"
            return 0
        fi
    }

    local remotefp="$1"
    remotefp="$(___x_cmd_hub_file_normalize_remotefp "$remotefp")"

    local resp
    resp="$(___x_cmd_hub_u_curl delete "/api/v0/file?res=$(___x_cmd url encode "$remotefp")&recurse=${recurse}&force=${force}")" || {
        ___x_cmd_hub_u_handle_resp false "Failed to rm file"
        return 1
    }
    ___x_cmd_hub_u_handle_resp true "Success to rm file"
}
