# shellcheck shell=dash

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

    local pkgnamelist="$___X_CMD_SNAP_APK_NAMELIST"

    while [ $# -gt 0 ]; do
        case "$1" in
            -h|--help)          ___x_cmd help -m dnf snap "$@" ;;
            -n|--namelist)      [ $# -ge 2 ] || N=dnf M="Please provide argument after $1" log:ret:64 ; pkgnamelist="$2"; shift 2 ;;
            *)                  break
        esac
    done

    local cmd="$1"; shift

    ___x_cmd_hascmd "$cmd" || {
        [ -n "$pkgnamelist" ] || {
            local x_=""
            if ___x_cmd snap --whichpkg_ dnf "$cmd"; then
                pkgnamelist="$x_"
            else
                pkgnamelist="$cmd"
            fi
        }

        ___x_cmd_dnf___haspriv || {
            dnf:error --next "sudo dnf install $pkgnamelist" \
                "You do not have permission. Please manually install $pkgnamelist"
            return 1
        }

        eval ___x_cmd_cmds dnf install -y "$pkgnamelist" || {
            dnf:error --next "dnf install -y $pkgnamelist"  \
                "Fail to isntall $pkgnamelist. You can try it manually"
            return 1
        }
    }

    ___x_cmd snap --runcmd "$cmd" "$@"
}


