feat(MenuSystem): Implement unified menu system for AzerothCore management (#22786)

This commit is contained in:
Yehonal
2025-09-04 00:03:55 +02:00
committed by GitHub
parent d5d8256bc5
commit 599d206584
7 changed files with 498 additions and 164 deletions
+81 -88
View File
@@ -1,114 +1,107 @@
#!/usr/bin/env bash
# AzerothCore Dashboard Script
#
# This script provides an interactive menu system for AzerothCore management
# using the unified menu system library.
#
# Usage:
# ./acore.sh - Interactive mode with numeric and text selection
# ./acore.sh <command> [args] - Direct command execution (only text commands, no numbers)
#
# Interactive Mode:
# - Select options by number (1, 2, 3...), command name (init, compiler, etc.),
# or short alias (i, c, etc.)
# - All selection methods work in interactive mode
#
# Direct Command Mode:
# - Only command names and short aliases are accepted (e.g., './acore.sh compiler build', './acore.sh c build')
# - Numeric selection is disabled to prevent confusion with command arguments
# - Examples: './acore.sh init', './acore.sh compiler clean', './acore.sh module install mod-name'
#
# Menu System:
# - Uses unified menu system from bash_shared/menu_system.sh
# - Single source of truth for menu definitions
# - Consistent behavior across all AzerothCore tools
CURRENT_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "$CURRENT_PATH/includes/includes.sh"
source "$AC_PATH_APPS/bash_shared/menu_system.sh"
PS3='[Please enter your choice]: '
options=(
"init (i): First Installation"
"install-deps (d): Configure OS dep"
"pull (u): Update Repository"
"reset (r): Reset & Clean Repository"
"compiler (c): Run compiler tool"
"module (m): Module manager (search/install/update/remove)"
"module-install (mi): Module Install by name [DEPRECATED]"
"module-update (mu): Module Update by name [DEPRECATED]"
"module-remove: (mr): Module Remove by name [DEPRECATED]"
"client-data: (gd): download client data from github repository (beta)"
"run-worldserver (rw): execute a simple restarter for worldserver"
"run-authserver (ra): execute a simple restarter for authserver"
"docker (dr): Run docker tools"
"version (v): Show AzerothCore version"
"service-manager (sm): Run service manager to run authserver and worldserver in background"
"quit (q): Exit from this menu"
)
# Menu: single ordered source of truth (no functions in strings)
# Format: "key|short|description"
menu_items=(
"init|i|First Installation"
"install-deps|d|Configure OS dep"
"pull|u|Update Repository"
"reset|r|Reset & Clean Repository"
"compiler|c|Run compiler tool"
"module|m|Module manager (search/install/update/remove)"
"client-data|gd|download client data from github repository (beta)"
"run-worldserver|rw|execute a simple restarter for worldserver"
"run-authserver|ra|execute a simple restarter for authserver"
"docker|dr|Run docker tools"
"version|v|Show AzerothCore version"
"service-manager|sm|Run service manager to run authserver and worldserver in background"
"quit|q|Exit from this menu"
)
function _switch() {
_reply="$1"
_opt="$2"
case $_reply in
""|"i"|"init")
inst_allInOne
# Menu command handler - called by menu system for each command
function handle_menu_command() {
local key="$1"
shift
case "$key" in
"init")
inst_allInOne
;;
""|"d"|"install-deps")
inst_configureOS
"install-deps")
inst_configureOS
;;
""|"u"|"pull")
inst_updateRepo
"pull")
inst_updateRepo
;;
""|"r"|"reset")
inst_resetRepo
"reset")
inst_resetRepo
;;
""|"c"|"compiler")
bash "$AC_PATH_APPS/compiler/compiler.sh" $_opt
"compiler")
bash "$AC_PATH_APPS/compiler/compiler.sh" "$@"
;;
""|"m"|"module")
# Unified module command: supports subcommands search|install|update|remove
inst_module "${@:2}"
"module")
bash "$AC_PATH_APPS/installer/includes/modules-manager/module-main.sh" "$@"
;;
""|"ms"|"module-search")
echo "[DEPRECATED] Use: ./acore.sh module search <terms...>"
inst_module_search "${@:2}"
"client-data")
inst_download_client_data
;;
""|"mi"|"module-install")
echo "[DEPRECATED] Use: ./acore.sh module install <modules...>"
inst_module_install "${@:2}"
"run-worldserver")
inst_simple_restarter worldserver
;;
""|"mu"|"module-update")
echo "[DEPRECATED] Use: ./acore.sh module update <modules...>"
inst_module_update "${@:2}"
"run-authserver")
inst_simple_restarter authserver
;;
""|"mr"|"module-remove")
echo "[DEPRECATED] Use: ./acore.sh module remove <modules...>"
inst_module_remove "${@:2}"
"docker")
DOCKER=1 bash "$AC_PATH_ROOT/apps/docker/docker-cmd.sh" "$@"
exit
;;
""|"gd"|"client-data")
inst_download_client_data
;;
""|"rw"|"run-worldserver")
inst_simple_restarter worldserver
;;
""|"ra"|"run-authserver")
inst_simple_restarter authserver
;;
""|"dr"|"docker")
DOCKER=1 bash "$AC_PATH_ROOT/apps/docker/docker-cmd.sh" "${@:2}"
exit
;;
""|"v"|"version")
# denoRunFile "$AC_PATH_APPS/installer/main.ts" "version"
"version")
printf "AzerothCore Rev. %s\n" "$ACORE_VERSION"
exit
exit
;;
""|"sm"|"service-manager")
bash "$AC_PATH_APPS/startup-scripts/src/service-manager.sh" "${@:2}"
exit
"service-manager")
bash "$AC_PATH_APPS/startup-scripts/src/service-manager.sh" "$@"
exit
;;
""|"q"|"quit")
"quit")
echo "Goodbye!"
exit
exit
;;
""|"--help")
echo "Available commands:"
printf '%s\n' "${options[@]}"
*)
echo "Invalid option. Use --help to see available commands."
return 1
;;
*) echo "invalid option, use --help option for the commands list";;
esac
}
while true
do
# run option directly if specified in argument
[ ! -z $1 ] && _switch $@ # old method: "${options[$cmdopt-1]}"
[ ! -z $1 ] && exit 0
echo "==== ACORE DASHBOARD ===="
select opt in "${options[@]}"
do
_switch $REPLY
break
done
echo "opt: $opt"
done
# Run the menu system
menu_run "ACORE DASHBOARD" handle_menu_command "${menu_items[@]}" "$@"