# shellcheck shell=dash

___X_CMD_BUN_LOADED=
___x_cmd_bun_loaded(){
    [ -n "$___X_CMD_BUN_LOADED" ]
}

___x_cmd_bun_load(){
    ! ___x_cmd_bun_loaded || return 0

    ___x_cmd_bun_load_checkenv || {
        bun:debug "Cannot find bun installed in this current environment"
        ___x_cmd_bun_load_env
        return
    }

    # TODO: In the future, we need to check the current version is good enough.

    ___X_CMD_BUN_LOADED=1
}

___X_CMD_BUN_SHIMAPP_PATH=
___x_cmd_bun_load_env(){
    [ -z "$___X_CMD_BUN_SHIMAPP_PATH" ] || return 0

    local x_=""
    ___x_cmd pkg sphere getbinpath_ "bun" "v1.2.2" "shim_bin"    || return
    ___X_CMD_BUN_SHIMAPP_PATH="$x_"
    ___X_CMD_BUN_LOADED="installable"
}

# TODO: Add yes and quiet in the future
___x_cmd_bun_load_checkenv(){
    ___x_cmd hascmd bun   || return
}
