# shellcheck shell=dash disable=SC2034,SC2016
___x_cmd log init yum

xrc:mod:lib  yum   __xmirror/_index  __repo __xproxy install nv

___x_cmd_yum___main(){
    [ "$#" -gt 0 ] ||   set -- fz
    local op="$1"; shift
    case "$op" in
        -h|--help)
            ___x_cmd help -m yum "$@"; return   ;;
    esac

    ___x_cmd hascmd yum || {
        yum:warn "yum command not found."
        return 1
    }

    case "$op" in
        install)            ___x_cmd_yum_install            "$@" ;;
        fz)                 ___x_cmd_yum___fz                   "$@" ;;
        --fzdata)           ___x_cmd_yum_install___fz_data      "$@" ;;
        --fzfpreview)       ___x_cmd_yum_install___fzf_preview  "$@" ;;

        proxy|--xproxy)     ___x_cmd_yum___xproxy           "$@" ;;
        mirror|--xmirror)   ___x_cmd_yum___xmirror          "$@" ;;


        # proxy)            ___x_cmd_yum___proxy    "$@"         ;;
        *)                  ___x_cmd_cmds yum "$op" "$@"         ;;
    esac
}

___x_cmd_yum___exec(){
    if [ "$(id -u)" -ne 0 ]; then
        yum:info "running command  →  x sudo yum $*"
        ___x_cmd_yum___xproxy run ___x_cmd sudo yum "$@"
    else
        ___x_cmd_yum___xproxy run ___x_cmd_cmds yum "$@"
    fi
}

___x_cmd_yum___lsraw(){
    local x_=; ___x_cmd_yum___lsraw_ || return 1
    ___x_cmd_cmds_cat "$x_"
}

___x_cmd_yum___lsraw_(){
    x_="$___X_CMD_ROOT_DATA/yum/cache/lsname"
    ___x_cmd ensurefp "$x_"
    local cache_fp
    if [ -f "/var/cache/dnf/fedora.solv" ]; then
        cache_fp="/var/cache/dnf/fedora.solv"
    else
        cache_fp="$(___x_cmd_cmds find "/var/cache/libdnf5" -name 'fedora.solv')"
    fi

    [ "$x_" -nt "$cache_fp" ] || {
        ___x_cmd rmrf "$x_"
        ___x_cmd_yum___repo_lsname > "$x_"
    }
    [ -f "$x_" ]
}

