# shellcheck shell=sh disable=SC3043

___X_CMD_GROOVY_LOADED=
___x_cmd_groovy_loaded(){
    [ -n "$___X_CMD_GROOVY_LOADED" ]
}

___x_cmd_groovy_load(){
    ! ___x_cmd_groovy_loaded || return 0

    ___x_cmd_groovy_load_checkenv || {
        groovy:warn "Cannot find groovy installed in this current environment"
        ___x_cmd_groovy_load_env
        return
    }

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

___x_cmd_groovy_load_env(){
    # TODO: add quiet
    groovy:info "Loading groovy in this shell env using 'x env try groovy'"
    ___x_cmd java load         || return
    ___x_cmd env try groovy    || return
}

# TODO: Add yes and quiet in the future
___x_cmd_groovy_load_checkenv(){
    ___x_cmd java checkenv     || return
    ___x_cmd hascmd groovy     || return
}
