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

View File

@@ -0,0 +1,7 @@
#!/usr/bin/env bash
CURRENT_PATH=$( cd "$(dirname "${BASH_SOURCE[0]}")" || exit ; pwd )
source "$CURRENT_PATH/modules.sh"
inst_module "$@"

View File

@@ -13,16 +13,126 @@
# - Cross-format module recognition (URLs, SSH, simple names)
# - Custom directory naming to prevent conflicts
# - Intelligent duplicate prevention
# - Interactive menu system for easy management
#
# Usage:
# source "path/to/modules.sh"
# inst_module_install "mod-transmog:my-custom-dir@develop:abc123"
# inst_module # Interactive menu
# inst_module search "transmog" # Direct command
#
# =============================================================================
CURRENT_PATH=$( cd "$(dirname "${BASH_SOURCE[0]}")" || exit ; pwd )
source "$CURRENT_PATH/../../../bash_shared/includes.sh"
source "$AC_PATH_APPS/bash_shared/menu_system.sh"
# Module management menu definition
# Format: "key|short|description"
module_menu_items=(
"search|s|Search for available modules"
"install|i|Install one or more modules"
"update|u|Update installed modules"
"remove|r|Remove installed modules"
"list|l|List installed modules"
"help|h|Show detailed help"
"quit|q|Close this menu"
)
# Menu command handler for module operations
function handle_module_command() {
local key="$1"
shift
case "$key" in
"search")
inst_module_search "$@"
;;
"install")
inst_module_install "$@"
;;
"update")
inst_module_update "$@"
;;
"remove")
inst_module_remove "$@"
;;
"list")
inst_module_list "$@"
;;
"help")
inst_module_help
;;
"quit")
echo "Exiting module manager..."
exit 0
;;
*)
echo "Invalid option. Use 'help' to see available commands."
return 1
;;
esac
}
# Show detailed module help
function inst_module_help() {
echo "AzerothCore Module Manager Help"
echo "==============================="
echo ""
echo "Usage:"
echo " ./acore.sh module # Interactive menu"
echo " ./acore.sh module search [terms...]"
echo " ./acore.sh module install [--all | modules...]"
echo " ./acore.sh module update [--all | modules...]"
echo " ./acore.sh module remove [modules...]"
echo " ./acore.sh module list # List installed modules"
echo ""
echo "Module Specification Syntax:"
echo " name # Simple name (e.g., mod-transmog)"
echo " owner/name # GitHub repository"
echo " name:branch # Specific branch"
echo " name:branch:commit # Specific commit"
echo " name:dirname@branch # Custom directory name"
echo " https://github.com/... # Full URL"
echo ""
echo "Examples:"
echo " ./acore.sh module install mod-transmog"
echo " ./acore.sh module install azerothcore/mod-transmog:develop"
echo " ./acore.sh module update --all"
echo " ./acore.sh module remove mod-transmog"
echo ""
}
# List installed modules
function inst_module_list() {
echo "Installed Modules:"
echo "=================="
local count=0
while read -r repo_ref branch commit; do
[[ -z "$repo_ref" ]] && continue
count=$((count + 1))
echo " $count. $repo_ref ($branch)"
if [[ "$commit" != "-" ]]; then
echo " Commit: $commit"
fi
done < <(inst_mod_list_read)
if [[ $count -eq 0 ]]; then
echo " No modules installed."
fi
echo ""
}
# Dispatcher for the unified `module` command.
# Usage: ./acore.sh module <search|install|update|remove> [args...]
# ./acore.sh module # Interactive menu
function inst_module() {
# If no arguments provided, start interactive menu
if [[ $# -eq 0 ]]; then
menu_run "MODULE MANAGER" handle_module_command "${module_menu_items[@]}"
return $?
fi
# Normalize arguments into an array
local tokens=()
read -r -a tokens <<< "$*"
@@ -31,12 +141,7 @@ function inst_module() {
case "$cmd" in
""|"help"|"-h"|"--help")
echo "Usage:"
echo " ./acore.sh module search [terms...]"
echo " ./acore.sh module install [--all | modules...]"
echo " modules can be specified as: name[:branch[:commit]]"
echo " ./acore.sh module update [modules...]"
echo " ./acore.sh module remove [modules...]"
inst_module_help
;;
"search"|"s")
inst_module_search "${args[@]}"
@@ -50,9 +155,13 @@ function inst_module() {
"remove"|"r")
inst_module_remove "${args[@]}"
;;
"list"|"l")
inst_module_list "${args[@]}"
;;
*)
echo "Unknown subcommand: $cmd"
echo "Try: ./acore.sh module help"
echo "Unknown module command: $cmd"
echo "Use 'help' to see available commands."
return 1
;;
esac
}

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[@]}" "$@"

View File

@@ -58,6 +58,9 @@ EOF
# minimal stub
EOF
# Copy the menu system needed by modules.sh
cp "$AC_TEST_ROOT/apps/bash_shared/menu_system.sh" "$TEST_DIR/apps/bash_shared/"
# Copy the real installer app into the test apps dir
mkdir -p "$TEST_DIR/apps"
cp -r "$(cd "$AC_TEST_ROOT/apps/installer" && pwd)" "$TEST_DIR/apps/installer"