From ef192b082541aad56da076a6fa883a7f83a80b85 2022-06-01 22:35:51 From: Branko Majic <branko@majic.rs> Date: 2022-06-01 22:35:51 Subject: [PATCH] Noticket: [factorio_manager.sh] Add verbose output for info command: - Lists mod URLs and their descriptions. --- diff --git a/games/factorio_manager.sh b/games/factorio_manager.sh index dfa33f706ed1ba857fd5d7a10bb5b6ee6f4299aa..c552dbca14b4a82230617dfab4b7012a68560cbb 100755 --- a/games/factorio_manager.sh +++ b/games/factorio_manager.sh @@ -145,6 +145,9 @@ info INSTANCE - list of enabled/disabled mods - list of backups + If verbose mode is enabled, mods are listed with URLs and + description as well. + install GAME_ARCHIVE Installs Factorio from the provided archive into the game @@ -214,6 +217,8 @@ $program accepts the following options: -C Force colour output. + -V + Verbose mode. Some commands may provide more output when enabled. -q Quiet mode. Output a message only if newer packages are available. -d @@ -1225,6 +1230,7 @@ ERROR_GENERAL=3 # Disable debug and quiet modes by default. debug=0 quiet=0 +verbose=0 force_colours=0 # Set-up some default paths. @@ -1239,8 +1245,9 @@ if [[ -z ${1-} ]]; then fi # Parse the arguments -while getopts "Cqdvh" opt; do +while getopts "VCqdvh" opt; do case "$opt" in + V) verbose=1;; C) force_colours=1;; q) # shellcheck disable=SC2034 # part of standard Bash script template. quiet=1;; @@ -1901,7 +1908,7 @@ elif [[ $command == info ]]; then echo "Available mods: none" # Listing using just regular tools. - elif ! hash jqs 2>/dev/null; then + elif ! hash jq 2>/dev/null; then echo "Available mods:" echo @@ -1936,6 +1943,17 @@ elif [[ $command == info ]]; then # Show colored-information for the mod. printf "$color - %-48s %8s $_text_reset\n" "$mod_name" "$mod_version" + if (( verbose == 1 )); then + mod_info=$(unzip -Z1 "$mod_file" | grep "info\.json" | head -n1) + mod_description=$(unzip -p "$mod_file" "$mod_info" | grep '"description":' | sed -e 's/\r//g;s/[^"]*"description": //;s/^"//;s/"$//') + mod_description=$(echo -e "$mod_description" | fold -s -w 50 | sed -e 's/^/ /') + mod_url="https://mods.factorio.com/mod/${mod_info}" + echo + echo " ($mod_url)" + echo + echo "$mod_description" + echo + fi fi done @@ -1983,6 +2001,16 @@ elif [[ $command == info ]]; then # Show colored-information for the mod. printf "$color - %-48s %8s $_text_reset\n" "$mod_name" "$mod_version" + if (( verbose == 1 )); then + mod_info=$(unzip -Z1 "$mod_file" | grep "info\.json" | head -n1) + mod_description=$(unzip -p "$mod_file" "$mod_info" | jq -r -e '.description' | fold -s -w 50 | sed -e 's/^/ /') + mod_url="https://mods.factorio.com/mod/${mod_info}" + echo + echo " ($mod_url)" + echo + echo "$mod_description" + echo + fi fi done fi