# shellcheck shell=dash

___x_cmd_bun___enginerun_hub(){
    local ___X_CMD_BUN_WHICHFILE=
    local x_=
    ___x_cmd_bun___setarg_ "$@" || return
    bun:debug "Args ==> $*"
    bun:debug "cmd x_ ==> $x_"
    [ -z "$x_" ] || eval "$x_"
    ___x_cmd_bun___cmd bun "$@"
}

___x_cmd_bun___enginerun(){
    case "$1" in
        -*|run|bun|test|x|repl|init|create|c|install|uninstall|add|a|\
        remove|rm|update|link|unlink|pm|build|upgrade|help)
            ___x_cmd_bun___enginerun_hub "$@"
            ;;
        *)
            local ___X_CMD_WHICH_ONE_RESULT=""
            if ___x_cmd_which_one "$1" 2>/dev/null && [ "$___X_CMD_WHICH_ONE_RESOURCE_TYPE" != "official" ]; then
                shift
                bun:debug "Found file ==> $___X_CMD_WHICH_ONE_RESULT"
                ___x_cmd_bun___cmd bun "$___X_CMD_WHICH_ONE_RESULT" "$@"
            else
                ___x_cmd_bun___cmd bun "$@"         # NOT eval that bun can run package.json scripts directly like bun lint => bun run lint
            fi
            ;;
    esac
}

