Changeset - ef192b082541
[Not reviewed]
0 1 0
Branko Majic (branko) - 2 years ago 2022-06-01 22:35:51
branko@majic.rs
Noticket: [factorio_manager.sh] Add verbose output for info command:

- Lists mod URLs and their descriptions.
1 file changed with 30 insertions and 2 deletions:
0 comments (0 inline, 0 general) First comment
games/factorio_manager.sh
Show inline comments
 
@@ -142,12 +142,15 @@ info INSTANCE
 
        - instance name
 
        - game version
 
        - instance directory path
 
        - 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
 
    installations directory. Version is automatically detected from
 
    the archive. All extracted game files are set-up to be read-only
 
    to prevent accidentally running the game directly from its own
 
@@ -211,12 +214,14 @@ versions
 

	
 

	
 
$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
 
        Enable debug mode.
 
    -v
 
        Show script licensing information.
 
@@ -1222,12 +1227,13 @@ ERROR_ARGUMENTS=1
 
ERROR_CONFIGURATION=2
 
ERROR_GENERAL=3
 

	
 
# Disable debug and quiet modes by default.
 
debug=0
 
quiet=0
 
verbose=0
 
force_colours=0
 

	
 
# Set-up some default paths.
 
manager_directory="$HOME/.factorio"
 
game_installations_directory="$manager_directory/.game_installations"
 

	
 
@@ -1236,14 +1242,15 @@ if [[ -z ${1-} ]]; then
 
    setup_colours
 
    short_usage
 
    exit "$SUCCESS"
 
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;;
 
	d) debug=1;;
 
        v) version
 
           exit "$SUCCESS";;
 
@@ -1898,13 +1905,13 @@ elif [[ $command == info ]]; then
 
    shopt -u nullglob
 

	
 
    if [[ ${#mod_files[@]} == 0 ]]; 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
 

	
 
        # Determine if mod is enabled by default or not when added to
 
        # mods directory (and is not yet listed in the mod list file).
 
        if grep -i -q "^[[:blank:]]*enable-new-mods=false" "$game_config"; then
 
@@ -1933,12 +1940,23 @@ elif [[ $command == info ]]; then
 
                else
 
                    color=""
 
                fi
 

	
 
                # 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
 

	
 
    # Listing using the jq utility.
 
    elif hash jq 2>/dev/null; then
 
@@ -1980,12 +1998,22 @@ elif [[ $command == info ]]; then
 
                else
 
                    color="$_text_yellow"
 
                fi
 

	
 
                # 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
 
    echo
 

	
 
    # Call self for displaying list of backups. Better than duplicating code.
0 comments (0 inline, 0 general) First comment
You need to be logged in to comment. Login now