
___x_cmd_trex___run(){
    local trex_root="$___X_CMD_TREX_ROOT"

    while [ $# -gt 0 ]; do
        case "$1" in
            --root)         shift;  trex_root="$1" ;;
            *)              break ;;
        esac
    done

    [ -n "$___X_CMD_TREX_ROOT" ]    ||  N=trex M="--root is required"           log:ret:1
    [ -d "$trex_root" ]             ||  N=trex M="Not a folder -> $trex_root"   log:ret:1

    trex_rp=""
    while [ $# -gt 0 ] && [ -d "${trex_root}${trex_rp}/${1}" ]; do
        trex_rp="${trex_rp}/${1}"
        shift
    done

    ___x_cmd_trex___runfp "$trex_root" "$trex_rp" "$@"
}

___x_cmd_trex___runfp(){
    local trex_root="$1"
    local trex_rp="$2"
    shift 2

    if [ -f "${trex_root}${trex_rp}" ]; then
        ___x_cmd_engine_run    "${trex_root}${trex_rp}"         "$@"
    elif [ -f "${trex_root}${trex_rp}/X" ]; then
        ___x_cmd_engine_run    "${trex_root}${trex_rp}/X"       "$@"
    elif [ -f "${trex_root}${trex_rp}/ws" ]; then
        # Deprecated in the future ...
        ___x_cmd_engine_run   "${trex_root}${trex_rp}/ws"       "$@"
    fi
}
