From b2fed9023c88517ac862fbdf8c5537b7abd66918 Mon Sep 17 00:00:00 2001 From: XargonWan Date: Thu, 20 Feb 2025 14:35:52 +0900 Subject: [PATCH] CLI: enhance preset configuration with case-insensitive options and improved help message --- functions/presets.sh | 8 +++++++- retrodeck.sh | 48 ++++++++++++++++++++++++-------------------- 2 files changed, 33 insertions(+), 23 deletions(-) diff --git a/functions/presets.sh b/functions/presets.sh index f6f7be02..39c2fd09 100644 --- a/functions/presets.sh +++ b/functions/presets.sh @@ -169,6 +169,12 @@ make_preset_changes() { choice="$2" force_state="${3:-}" + if [[ "${force_state,,}" == "on" || "${force_state,,}" == "true" ]]; then + force_state="true" + elif [[ "${force_state,,}" == "off" || "${force_state,,}" == "false" ]]; then + force_state="false" + fi + log d "Building preset list options for preset: $preset" build_preset_list_options "$preset" @@ -185,7 +191,7 @@ make_preset_changes() { for emulator in "${choices[@]}"; do if [[ -n "$force_state" ]]; then new_state="$force_state" - log d "Forcing $preset to state: $new_state for $emulator" + log i "Forcing $preset to state: $new_state for $emulator" else current_state=$(get_setting_value "$rd_conf" "$emulator" "retrodeck" "$preset") if [[ "$current_state" == "true" ]]; then diff --git a/retrodeck.sh b/retrodeck.sh index 17005ccd..6dee7638 100644 --- a/retrodeck.sh +++ b/retrodeck.sh @@ -17,7 +17,7 @@ Arguments: --reset \t Reset RetroDECK or one or more component/emulator configurations to default values. WARNING: no confirmation prompt --factory-reset \t Factory Reset, triggers the initial setup WARNING: no confirmation prompt --test-upgrade \t Test upgrading RetroDECK to a specific version, developer use only - --set [value] \t Configure or toggle a preset. Examples: --set borders, --set borders all true,\n\t\t\t\t\t\t --set borders gba false. Use --set help for more information + --set [value] \t Configure or toggle a preset. Examples: --set borders, --set borders all true,\n\t\t\t\t\t\t --set borders gba false. Use --set-help for more information --open \t Open a specific component or emulator\n\t\t\t\t\t\t --open --list for a list of available components Game Launch: @@ -67,6 +67,24 @@ case "$1" in cat "$rd_conf" exit 0 ;; + --set-help) + LOG_SILENT=true + source /app/libexec/global.sh + echo -e "\nUsed to toggle or set a preset.\n\nAvailable presets are:" + fetch_all_presets | tr ' ' ',' | sed 's/,/, /g' + echo -e "\nUsage: --set [value]" + echo -e "\nExamples:" + echo -e " Force borders to be ON for GBA:" + echo -e " make_preset_changes borders gba on" + echo -e " Force borders to be OFF for all supported systems:" + echo -e " make_preset_changes borders all off" + echo -e " Toggle GBA in preset borders (this will disable if enabled and vice versa):" + echo -e " make_preset_changes borders gba" + echo -e " Toggle all in preset borders:" + echo -e " make_preset_changes borders all" + echo -e "\nYou can also use 'true' or 'false' instead of 'on' and 'off'.\nThe forced status is case insensitive." + exit 0 + ;; esac source /app/libexec/global.sh @@ -132,31 +150,17 @@ while [[ $# -gt 0 ]]; do ;; --set) preset="$2" + system="$3" + value="$4" if [ "$preset" == "cheevos" ]; then - echo "Error: The 'cheevos' preset is not yet supported via CLI. Please use the RetroDECK Configurator." - exit 1 + echo "Error: The 'cheevos' preset is not yet supported via CLI. Please use the RetroDECK Configurator." + exit 1 fi - value="$3" if [ -z "$preset" ]; then - echo "Error: No preset specified. Usage: --set [value] (use --set help for more information)" - exit 1 + echo "Error: No preset specified. Usage: --set [value] (use --set-help for more information)" + exit 1 fi - if [ "$preset" == "help" ]; then - echo "Used to toggle or set a preset. Available presets are:" - fetch_all_presets - echo "Usage: --set [value]" - echo "Examples:" - echo " Force borders to be true for GBA:" - echo " make_preset_changes borders gba true" - echo " Force borders to be true for all supported systems:" - echo " make_preset_changes borders all true" - echo " Toggle GBA in preset borders (this will disable if enabled and vice versa):" - echo " make_preset_changes borders gba true" - echo " Toggle all in preset borders:" - echo " make_preset_changes borders all" - exit 0 - fi - make_preset_changes "$preset" "$value" + make_preset_changes "$preset" "$system" "$value" exit 0 ;; --open)