mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2025-11-29 17:38:24 +08:00
Refactor menu command handling for direct execution (#22791)
This commit is contained in:
18
.github/workflows/dashboard-ci.yml
vendored
18
.github/workflows/dashboard-ci.yml
vendored
@@ -80,12 +80,30 @@ jobs:
|
|||||||
# Configure dashboard
|
# Configure dashboard
|
||||||
sed -i 's/MTHREADS=.*/MTHREADS="4"/' conf/config.sh
|
sed -i 's/MTHREADS=.*/MTHREADS="4"/' conf/config.sh
|
||||||
|
|
||||||
|
- name: Test module commands
|
||||||
|
run: |
|
||||||
|
./acore.sh module install mod-autobalance
|
||||||
|
./acore.sh module install mod-duel-reset
|
||||||
|
|
||||||
|
./acore.sh module list
|
||||||
|
|
||||||
|
./acore.sh module install --all
|
||||||
|
./acore.sh module update mod-autobalance
|
||||||
|
./acore.sh module update --all
|
||||||
|
|
||||||
- name: Run complete installation (deps, compile, database, client-data)
|
- name: Run complete installation (deps, compile, database, client-data)
|
||||||
run: |
|
run: |
|
||||||
# This runs: install-deps, compile, database setup, client-data download
|
# This runs: install-deps, compile, database setup, client-data download
|
||||||
./acore.sh init
|
./acore.sh init
|
||||||
timeout-minutes: 120
|
timeout-minutes: 120
|
||||||
|
|
||||||
|
- name: Test module removal
|
||||||
|
run: |
|
||||||
|
./acore.sh module remove mod-autobalance
|
||||||
|
./acore.sh module list
|
||||||
|
./acore.sh module remove mod-duel-reset
|
||||||
|
./acore.sh module list
|
||||||
|
|
||||||
- name: Test authserver dry-run
|
- name: Test authserver dry-run
|
||||||
run: |
|
run: |
|
||||||
cd env/dist/bin
|
cd env/dist/bin
|
||||||
|
|||||||
@@ -102,13 +102,6 @@ function menu_direct_execute() {
|
|||||||
local user_input="$1"
|
local user_input="$1"
|
||||||
shift
|
shift
|
||||||
|
|
||||||
# Handle help requests directly
|
|
||||||
if [[ "$user_input" == "--help" || "$user_input" == "help" || "$user_input" == "-h" ]]; then
|
|
||||||
echo "Available commands:"
|
|
||||||
printf '%s\n' "${_MENU_OPTIONS[@]}"
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Disable numeric selection in direct mode
|
# Disable numeric selection in direct mode
|
||||||
if [[ "$user_input" =~ ^[0-9]+$ ]]; then
|
if [[ "$user_input" =~ ^[0-9]+$ ]]; then
|
||||||
echo "Invalid option. Numeric selection is not allowed when passing arguments."
|
echo "Invalid option. Numeric selection is not allowed when passing arguments."
|
||||||
@@ -118,11 +111,25 @@ function menu_direct_execute() {
|
|||||||
|
|
||||||
# Find command and execute
|
# Find command and execute
|
||||||
local idx
|
local idx
|
||||||
idx=$(menu_find_index "$user_input")
|
# try-catch
|
||||||
|
{
|
||||||
|
idx=$(menu_find_index "$user_input")
|
||||||
|
} ||
|
||||||
|
{
|
||||||
|
idx=-1
|
||||||
|
}
|
||||||
|
|
||||||
if [[ $idx -ge 0 ]]; then
|
if [[ $idx -ge 0 ]]; then
|
||||||
"$callback" "${_MENU_KEYS[$idx]}" "$@"
|
"$callback" "${_MENU_KEYS[$idx]}" "$@"
|
||||||
return $?
|
return $?
|
||||||
else
|
else
|
||||||
|
# Handle help requests directly
|
||||||
|
if [[ "$user_input" == "--help" || "$user_input" == "help" || "$user_input" == "-h" ]]; then
|
||||||
|
echo "Available commands:"
|
||||||
|
printf '%s\n' "${_MENU_OPTIONS[@]}"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
echo "Invalid option. Use --help to see available commands." >&2
|
echo "Invalid option. Use --help to see available commands." >&2
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
@@ -138,20 +145,32 @@ function menu_interactive() {
|
|||||||
menu_display "$title"
|
menu_display "$title"
|
||||||
read -r -p "Please enter your choice: " REPLY
|
read -r -p "Please enter your choice: " REPLY
|
||||||
|
|
||||||
# Handle help request
|
# Parse input to separate command from arguments
|
||||||
if [[ "$REPLY" == "--help" || "$REPLY" == "help" || "$REPLY" == "h" ]]; then
|
local input_parts=()
|
||||||
echo "Available commands:"
|
read -r -a input_parts <<< "$REPLY"
|
||||||
printf '%s\n' "${_MENU_OPTIONS[@]}"
|
local user_command="${input_parts[0]}"
|
||||||
echo ""
|
local user_args=("${input_parts[@]:1}")
|
||||||
continue
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Find and execute command
|
# Find and execute command
|
||||||
local idx
|
local idx
|
||||||
idx=$(menu_find_index "$REPLY")
|
idx=$(menu_find_index "$user_command")
|
||||||
if [[ $idx -ge 0 ]]; then
|
if [[ $idx -ge 0 ]]; then
|
||||||
"$callback" "${_MENU_KEYS[$idx]}"
|
# Pass the command key and any additional arguments
|
||||||
|
"$callback" "${_MENU_KEYS[$idx]}" "${user_args[@]}"
|
||||||
|
local exit_code=$?
|
||||||
|
# Exit loop if callback returns 0 (e.g., quit command)
|
||||||
|
if [[ $exit_code -eq 0 && "${_MENU_KEYS[$idx]}" == "quit" ]]; then
|
||||||
|
break
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
|
# Handle help request
|
||||||
|
if [[ "$REPLY" == "--help" || "$REPLY" == "help" || "$REPLY" == "h" ]]; then
|
||||||
|
echo "Available commands:"
|
||||||
|
printf '%s\n' "${_MENU_OPTIONS[@]}"
|
||||||
|
echo ""
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
echo "Invalid option. Please try again or use 'help' for available commands." >&2
|
echo "Invalid option. Please try again or use 'help' for available commands." >&2
|
||||||
echo ""
|
echo ""
|
||||||
fi
|
fi
|
||||||
@@ -159,35 +178,65 @@ function menu_interactive() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Main menu runner function
|
# Main menu runner function
|
||||||
# Usage: menu_run "Menu Title" callback_function menu_item1 menu_item2 ... "$@"
|
# Usage: menu_run "Menu Title" callback_function "$@"
|
||||||
|
# The menu items array should be defined globally before calling this function
|
||||||
function menu_run() {
|
function menu_run() {
|
||||||
local title="$1"
|
local title="$1"
|
||||||
local callback="$2"
|
local callback="$2"
|
||||||
shift 2
|
shift 2
|
||||||
|
|
||||||
# Extract menu items (all arguments until we find command line args)
|
# Define menu from globally available menu items array
|
||||||
local menu_items=()
|
# This expects the calling script to have set up the menu items
|
||||||
local found_args=false
|
|
||||||
|
|
||||||
# Separate menu items from command line arguments
|
# Handle direct execution if arguments provided
|
||||||
while [[ $# -gt 0 ]]; do
|
if [[ $# -gt 0 ]]; then
|
||||||
if [[ "$1" =~ \| ]]; then
|
menu_direct_execute "$callback" "$@"
|
||||||
# This looks like a menu item (contains pipe)
|
return $?
|
||||||
menu_items+=("$1")
|
fi
|
||||||
shift
|
|
||||||
else
|
# Run interactive menu
|
||||||
# This is a command line argument
|
menu_interactive "$callback" "$title"
|
||||||
found_args=true
|
}
|
||||||
break
|
|
||||||
fi
|
# Alternative menu runner that accepts menu items directly
|
||||||
|
# Usage: menu_run_with_items "Menu Title" callback_function -- "${menu_items_array[@]}" -- "$@"
|
||||||
|
function menu_run_with_items() {
|
||||||
|
local title="$1"
|
||||||
|
local callback="$2"
|
||||||
|
shift 2
|
||||||
|
|
||||||
|
# Parse parameters: menu items are between first and second "--"
|
||||||
|
local menu_items=()
|
||||||
|
local script_args=()
|
||||||
|
|
||||||
|
# Skip first "--"
|
||||||
|
if [[ "$1" == "--" ]]; then
|
||||||
|
shift
|
||||||
|
else
|
||||||
|
echo "Error: menu_run_with_items requires -- separator before menu items" >&2
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Collect menu items until second "--"
|
||||||
|
while [[ $# -gt 0 && "$1" != "--" ]]; do
|
||||||
|
menu_items+=("$1")
|
||||||
|
shift
|
||||||
done
|
done
|
||||||
|
|
||||||
# Define menu from collected items
|
# Skip second "--" if present
|
||||||
|
if [[ "$1" == "--" ]]; then
|
||||||
|
shift
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Remaining args are script arguments
|
||||||
|
script_args=("$@")
|
||||||
|
|
||||||
|
# Define menu from provided array
|
||||||
menu_define "${menu_items[@]}"
|
menu_define "${menu_items[@]}"
|
||||||
|
|
||||||
# Handle direct execution if arguments provided
|
# Handle direct execution if arguments provided
|
||||||
if [[ $found_args == true ]]; then
|
if [[ ${#script_args[@]} -gt 0 ]]; then
|
||||||
menu_direct_execute "$callback" "$@"
|
menu_direct_execute "$callback" "${script_args[@]}"
|
||||||
return $?
|
return $?
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ function handle_compiler_command() {
|
|||||||
;;
|
;;
|
||||||
"quit")
|
"quit")
|
||||||
echo "Closing compiler menu..."
|
echo "Closing compiler menu..."
|
||||||
exit 0
|
return 0
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "Invalid option. Use --help to see available commands."
|
echo "Invalid option. Use --help to see available commands."
|
||||||
@@ -61,20 +61,5 @@ function handle_compiler_command() {
|
|||||||
# Hook support (preserved from original)
|
# Hook support (preserved from original)
|
||||||
runHooks "ON_AFTER_OPTIONS" # you can create your custom options
|
runHooks "ON_AFTER_OPTIONS" # you can create your custom options
|
||||||
|
|
||||||
# Legacy switch function (preserved for compatibility)
|
|
||||||
function _switch() {
|
|
||||||
local reply="$1"
|
|
||||||
local opt="$2"
|
|
||||||
|
|
||||||
case "$reply" in
|
|
||||||
""|"--help")
|
|
||||||
menu_show_help
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
run_option "$reply" "$opt"
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
}
|
|
||||||
|
|
||||||
# Run the menu system
|
# Run the menu system
|
||||||
menu_run "ACORE COMPILER" handle_compiler_command "${comp_menu_items[@]}" "$@"
|
menu_run_with_items "ACORE COMPILER" handle_compiler_command -- "${comp_menu_items[@]}" -- "$@"
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
CURRENT_PATH=$( cd "$(dirname "${BASH_SOURCE[0]}")" || exit ; pwd )
|
CURRENT_PATH=$( cd "$(dirname "${BASH_SOURCE[0]}")" || exit ; pwd )
|
||||||
|
|
||||||
source "$CURRENT_PATH/../../../bash_shared/includes.sh"
|
source "$CURRENT_PATH/../../../bash_shared/includes.sh"
|
||||||
|
source "$CURRENT_PATH/../includes.sh"
|
||||||
source "$AC_PATH_APPS/bash_shared/menu_system.sh"
|
source "$AC_PATH_APPS/bash_shared/menu_system.sh"
|
||||||
|
|
||||||
# Module management menu definition
|
# Module management menu definition
|
||||||
@@ -65,7 +66,7 @@ function handle_module_command() {
|
|||||||
;;
|
;;
|
||||||
"quit")
|
"quit")
|
||||||
echo "Exiting module manager..."
|
echo "Exiting module manager..."
|
||||||
exit 0
|
return 0
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "Invalid option. Use 'help' to see available commands."
|
echo "Invalid option. Use 'help' to see available commands."
|
||||||
@@ -129,7 +130,7 @@ function inst_module_list() {
|
|||||||
function inst_module() {
|
function inst_module() {
|
||||||
# If no arguments provided, start interactive menu
|
# If no arguments provided, start interactive menu
|
||||||
if [[ $# -eq 0 ]]; then
|
if [[ $# -eq 0 ]]; then
|
||||||
menu_run "MODULE MANAGER" handle_module_command "${module_menu_items[@]}"
|
menu_run_with_items "MODULE MANAGER" handle_module_command -- "${module_menu_items[@]}" --
|
||||||
return $?
|
return $?
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -727,6 +728,12 @@ function inst_module_install {
|
|||||||
|
|
||||||
# Update one or more modules
|
# Update one or more modules
|
||||||
function inst_module_update {
|
function inst_module_update {
|
||||||
|
# Handle help request
|
||||||
|
if [[ "$1" == "--help" || "$1" == "-h" ]]; then
|
||||||
|
inst_module_help
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
# Support multiple modules and the --all flag; prompt if none specified.
|
# Support multiple modules and the --all flag; prompt if none specified.
|
||||||
local args=("$@")
|
local args=("$@")
|
||||||
local use_all=false
|
local use_all=false
|
||||||
|
|||||||
@@ -104,4 +104,4 @@ function handle_menu_command() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Run the menu system
|
# Run the menu system
|
||||||
menu_run "ACORE DASHBOARD" handle_menu_command "${menu_items[@]}" "$@"
|
menu_run_with_items "ACORE DASHBOARD" handle_menu_command -- "${menu_items[@]}" -- "$@"
|
||||||
|
|||||||
Reference in New Issue
Block a user