CLI: enhance preset configuration with case-insensitive options and improved help message
Some checks are pending
Build RetroDECK / Build_RetroDECK (push) Waiting to run
Build RetroDECK / GitHub-publish (push) Blocked by required conditions
Build RetroDECK / Automated_Tests (push) Blocked by required conditions

This commit is contained in:
XargonWan 2025-02-20 14:35:52 +09:00
parent acf31654d5
commit b2fed9023c
2 changed files with 33 additions and 23 deletions

View file

@ -169,6 +169,12 @@ make_preset_changes() {
choice="$2" choice="$2"
force_state="${3:-}" 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" log d "Building preset list options for preset: $preset"
build_preset_list_options "$preset" build_preset_list_options "$preset"
@ -185,7 +191,7 @@ make_preset_changes() {
for emulator in "${choices[@]}"; do for emulator in "${choices[@]}"; do
if [[ -n "$force_state" ]]; then if [[ -n "$force_state" ]]; then
new_state="$force_state" 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 else
current_state=$(get_setting_value "$rd_conf" "$emulator" "retrodeck" "$preset") current_state=$(get_setting_value "$rd_conf" "$emulator" "retrodeck" "$preset")
if [[ "$current_state" == "true" ]]; then if [[ "$current_state" == "true" ]]; then

View file

@ -17,7 +17,7 @@ Arguments:
--reset <component> \t Reset RetroDECK or one or more component/emulator configurations to default values. WARNING: no confirmation prompt --reset <component> \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 --factory-reset \t Factory Reset, triggers the initial setup WARNING: no confirmation prompt
--test-upgrade <version> \t Test upgrading RetroDECK to a specific version, developer use only --test-upgrade <version> \t Test upgrading RetroDECK to a specific version, developer use only
--set <preset> <system/all> [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 <preset> <system/all> [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 <component/emulator> \t Open a specific component or emulator\n\t\t\t\t\t\t --open --list for a list of available components --open <component/emulator> \t Open a specific component or emulator\n\t\t\t\t\t\t --open --list for a list of available components
Game Launch: Game Launch:
@ -67,6 +67,24 @@ case "$1" in
cat "$rd_conf" cat "$rd_conf"
exit 0 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 <preset> <system/all> [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 esac
source /app/libexec/global.sh source /app/libexec/global.sh
@ -132,31 +150,17 @@ while [[ $# -gt 0 ]]; do
;; ;;
--set) --set)
preset="$2" preset="$2"
system="$3"
value="$4"
if [ "$preset" == "cheevos" ]; then if [ "$preset" == "cheevos" ]; then
echo "Error: The 'cheevos' preset is not yet supported via CLI. Please use the RetroDECK Configurator." echo "Error: The 'cheevos' preset is not yet supported via CLI. Please use the RetroDECK Configurator."
exit 1 exit 1
fi fi
value="$3"
if [ -z "$preset" ]; then if [ -z "$preset" ]; then
echo "Error: No preset specified. Usage: --set <preset> [value] (use --set help for more information)" echo "Error: No preset specified. Usage: --set <preset> <system/all> [value] (use --set-help for more information)"
exit 1 exit 1
fi fi
if [ "$preset" == "help" ]; then make_preset_changes "$preset" "$system" "$value"
echo "Used to toggle or set a preset. Available presets are:"
fetch_all_presets
echo "Usage: --set <preset> [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"
exit 0 exit 0
;; ;;
--open) --open)