# shellcheck shell=dash
___x_cmd log init ncdu

xrc:mod:lib     ncdu     load

___x_cmd_ncdu___main(){
    [ "$#" -gt 0 ] || {
        ___x_cmd_ncdu___cmd
        return
    }

    local op="$1";          shift
    case "$op" in
        -h|--help)      ___x_cmd help -m ncdu         "$@" ;;
        --preparecmd)   ___x_cmd_ncdu___preparecmd    "$@" ;;
        --|--cmd)       ___x_cmd_ncdu___cmd           "$@" ;;
        *)              ___x_cmd_ncdu___cmd "$op"     "$@" ;;
    esac
}

___x_cmd_ncdu___cmd(){
    if ___x_cmd_hascmd ncdu; then
        ___x_cmd_ncdu___cmd(){
            command ncdu "$@"
        }
    else
        ___x_cmd_ncdu___cmd(){
            ___x_cmd_ncdu_load_env || return
            "$___X_CMD_NCDU_SHIMAPP_PATH/ncdu" "$@"
        }
    fi

    ___x_cmd_ncdu___cmd "$@"
}

___x_cmd_ncdu___preparecmd(){
    ! ___x_cmd hascmd ncdu || return 0
    ___x_cmd_ncdu_load_env
}
