From 9bf3870befd332980b9175da2d080340c5ed845e 2020-07-06 17:07:18 From: Branko Majic <branko@majic.rs> Date: 2020-07-06 17:07:18 Subject: [PATCH] Noticket: [factorio_manager.sh] Disable a couple of false positives from shellcheck, and do not use $? when checking flock's exit code. --- diff --git a/games/factorio_manager.sh b/games/factorio_manager.sh index 00279e8a303a4c71579b7120833f62ea35bd5a76..ccf1d99b2dda69b109d6b6945b9a538f51c9d495 100755 --- a/games/factorio_manager.sh +++ b/games/factorio_manager.sh @@ -406,6 +406,9 @@ function colorprintf() { local format="$2" shift 2 + # Variables within this printf are used for dynamic color and + # formatting, and can't be used as arguments. + # shellcheck disable=SC2059 printf "${_text_colors[$color]}${format}${reset}" "$@" } @@ -1145,8 +1148,7 @@ function lock() { # Obtain lock - Factorio uses the same mechanism, so we should # be able to detect the game is running in this way. - flock --exclusive --nonblock "$fd" - if [[ $? != 0 ]]; then + if ! flock --exclusive --nonblock "$fd"; then error "Could not acquire lock via lock file '$lock_file'. Is Factorio still running?" exit "$ERROR_GENERAL" fi @@ -1280,6 +1282,7 @@ elif [[ $command == list ]]; then if [[ -f $candidate/instance.conf ]]; then # shellcheck source=/dev/null source "$candidate/instance.conf" + # shellcheck disable=SC2154 # game_version is read from the configuration file echo " - $(basename "$candidate") ($game_version)" fi done @@ -1883,6 +1886,7 @@ elif [[ $command == info ]]; then # single-quoted, and that $ expansions are actually done # internally in jq itself. Query accepts two vars - mod_name # and enable_new_mods. + # shellcheck disable=SC2016 # The $enable_new_mods is meant to be interpreted by jq, not bash. jq_is_enabled_query='.mods | map(select(.name==$mod_name))[0] // {"name": "default", "enabled": $enable_new_mods} | .enabled' # Process every mod found.