# Author:       Li Junhao           l@x-cmd.com     # xrc
# shellcheck    shell=sh            disable=SC3043,SC2164,SC3000-SC4000
# License:      GPLv3

xrc pkg

___x_cmd log init env
xrc:mod:lib env     _index util use_try app/lsenv var/_index apply boot exec ls __xinstall ll

___x_cmd_env___main(){
    [ $# -gt 0 ]    ||      set -- --app
    local op="$1";  shift
    case "$op" in
        --help|-h)                  ___x_cmd help -m env; return ;;
    esac

    ___x_cmd_is_suitable_pkg || {
        env:error "The env module functionality is not supported in the current environment"
        return 1
    }
    case "$op" in
        --xinstall)                 ___x_cmd_env___xinstall "$@" ;;

        ls)                         ___x_cmd_env_ls         "$@" ;;
        ll)                         ___x_cmd_env_ll              ;;
        la)                         ___x_cmd_env_ls -a      "$@" ;;

        try)                        ___x_cmd_env_try        "$@" ;;
        untry)                      ___x_cmd_env_untry      "$@" ;;
        u|use)                      ___x_cmd_env_use        "$@" ;;
        unuse)                      ___x_cmd_env_unuse      "$@" ;;
        upgrade)                    ___x_cmd_env_upgrade    "$@" ;;

        exec)                       ___x_cmd_env_exec       "$@" ;;
        boot)                       ___x_cmd_env_boot       "$@" ;;
        # prune)                      shift; ___x_cmd_env_prune       "$@" ;;
        unboot)                     ___x_cmd_env_unboot     "$@" ;;
        # sociality)                  shift; ___x_cmd_env_sociality   "$@" ;;
        gc|cleanup)                 ___x_cmd_env_gc         "$@" ;;
        depend)                     ___x_cmd_env_depend     "$@" ;;

        which)                      ___x_cmd_env_which      "$@" ;;
        var)                        ___x_cmd_env_var        "$@" ;;

        # apply)                    ___x_cmd_env_apply       "$@" ;;
        # revert)                   ___x_cmd_env_revert      "$@" ;;

        ""|--app)                   ___x_cmd_env_tuiapp;            return ;;
        *)                          ___x_cmd help -m env 1>&2;      return 64;;
    esac
}

___X_CMD_ENV_VERSION="v0.0.6"

___x_cmd_env_tuiapp(){
    if ___x_cmd_is_stdout2tty && ___x_cmd_runmode_allow_chatty; then
        ___x_cmd_env_choose_after_ui
    else
        ___x_cmd help -m env
    fi
}

