Skip to content

Commit e3462b5

Browse files
committed
A little militant cleanup
1 parent a6cafb6 commit e3462b5

21 files changed

Lines changed: 98 additions & 76 deletions

bin/terraform

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ if [ -z "${TFENV_ROOT:-""}" ]; then
2626
};
2727
TFENV_SHIM=$(readlink_f "${0}")
2828
TFENV_ROOT="${TFENV_SHIM%/*/*}";
29-
[ -n "${TFENV_ROOT}" ] || early_death "Failed to determine TFENV_ROOT"
29+
[ -n "${TFENV_ROOT}" ] || early_death "Failed to determine TFENV_ROOT";
3030
else
3131
TFENV_ROOT="${TFENV_ROOT%/}";
3232
fi;
@@ -47,7 +47,7 @@ fi;
4747
for dir in libexec bin; do
4848
case ":${PATH}:" in
4949
*:${TFENV_ROOT}/${dir}:*) log 'debug' "\$PATH already contains '${TFENV_ROOT}/${dir}', not adding it again";;
50-
*)
50+
*)
5151
log 'debug' "\$PATH does not contain '${TFENV_ROOT}/${dir}', prepending and exporting it now";
5252
export PATH="${TFENV_ROOT}/${dir}:${PATH}";
5353
;;
@@ -62,4 +62,4 @@ log 'debug' "program=\"${0##*/}\"";
6262

6363
declare tfenv_path="${TFENV_ROOT}/bin/tfenv";
6464

65-
tfenv-exec "$@"
65+
tfenv-exec "$@";

bin/tfenv

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ if [ -z "${TFENV_ROOT:-""}" ]; then
2626
};
2727
TFENV_SHIM=$(readlink_f "${0}")
2828
TFENV_ROOT="${TFENV_SHIM%/*/*}";
29-
[ -n "${TFENV_ROOT}" ] || early_death "Failed to determine TFENV_ROOT"
29+
[ -n "${TFENV_ROOT}" ] || early_death "Failed to determine TFENV_ROOT";
3030

3131
else
3232
TFENV_ROOT="${TFENV_ROOT%/}";
@@ -48,7 +48,7 @@ fi;
4848
for dir in libexec bin; do
4949
case ":${PATH}:" in
5050
*:${TFENV_ROOT}/${dir}:*) log 'debug' "\$PATH already contains '${TFENV_ROOT}/${dir}', not adding it again";;
51-
*)
51+
*)
5252
log 'debug' "\$PATH does not contain '${TFENV_ROOT}/${dir}', prepending and exporting it now";
5353
export PATH="${TFENV_ROOT}/${dir}:${PATH}";
5454
;;
@@ -62,7 +62,7 @@ done;
6262
declare arg="${1:-""}";
6363

6464
log 'debug' "Setting TFENV_DIR to ${PWD}";
65-
export TFENV_DIR="${PWD}"
65+
export TFENV_DIR="${PWD}";
6666

6767
abort() {
6868
log 'debug' 'Aborting...';

lib/bashlog.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ function log() {
6565
local severities_ALERT=1; # Unused
6666
local severities_EMERG=0; # Unused
6767

68-
local severity_var="severities_${upper}"
69-
local severity="${!severity_var:-3}"
68+
local severity_var="severities_${upper}";
69+
local severity="${!severity_var:-3}";
7070

7171
if [ "${debug_level}" -gt 0 ] || [ "${severity}" -lt 7 ]; then
7272

@@ -111,7 +111,7 @@ function log() {
111111
local colours_DEFAULT='\033[0m' # Default
112112

113113
local norm="${colours_DEFAULT}";
114-
local colour_var="colours_${upper}"
114+
local colour_var="colours_${upper}";
115115
local colour="${!colour_var:-\033[31m}";
116116

117117
local std_line;

lib/helpers.sh

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ if [ -z "${TFENV_ROOT:-""}" ]; then
1818
};
1919
TFENV_SHIM=$(readlink_f "${0}")
2020
TFENV_ROOT="${TFENV_SHIM%/*/*}";
21-
[ -n "${TFENV_ROOT}" ] || early_death "Failed to determine TFENV_ROOT"
21+
[ -n "${TFENV_ROOT}" ] || early_death "Failed to determine TFENV_ROOT";
2222
else
2323
TFENV_ROOT="${TFENV_ROOT%/}";
2424
fi;
@@ -44,23 +44,24 @@ fi;
4444

4545
function load_bashlog () {
4646
source "${TFENV_ROOT}/lib/bashlog.sh";
47-
}
47+
};
4848
export -f load_bashlog;
49+
4950
if [ "${TFENV_DEBUG:-0}" -gt 0 ] ; then
5051
# our shim below cannot be used when debugging is enabled
51-
load_bashlog
52+
load_bashlog;
5253
else
5354
# Shim that understands to no-op for debug messages, and defers to
5455
# full bashlog for everything else.
5556
function log () {
5657
if [ "$1" != 'debug' ] ; then
5758
# Loading full bashlog will overwrite the `log` function
58-
load_bashlog
59-
log "$@"
60-
fi
61-
}
59+
load_bashlog;
60+
log "$@";
61+
fi;
62+
};
6263
export -f log;
63-
fi
64+
fi;
6465

6566
resolve_version () {
6667
declare version_requested version regex min_required version_file;
@@ -78,10 +79,10 @@ resolve_version () {
7879
fi
7980

8081
if [ -z "${version_requested:-""}" ]; then
81-
log 'debug' 'Tryng to set version from "required_version" under "terraform" section'
82+
log 'debug' 'Trying to set version from "required_version" under "terraform" section';
8283
versions="$( echo $(cat {*.tf,*.tf.json} 2>/dev/null | grep -h required_version) | grep -o '\([0-9]\+\.\?\)\{2,3\}\(-[a-z]\+[0-9]\+\)\?')";
8384
if [[ "${versions}" =~ ([~=!<>]{0,2}[[:blank:]]*[0-9]+[0-9.]+)[^0-9]*(-[a-z]+[0-9]+)? ]]; then
84-
found_min_required="${BASH_REMATCH[1]}${BASH_REMATCH[2]}"
85+
found_min_required="${BASH_REMATCH[1]}${BASH_REMATCH[2]}";
8586
if [[ "${found_min_required}" =~ ^!=.+ ]]; then
8687
log 'debug' "required_version is a negation - we cannot guess the desired one, skipping.";
8788
else
@@ -145,7 +146,7 @@ resolve_version () {
145146
regex="^${version_requested}$";
146147
log 'debug' "Version is explicit: ${version}. Regex enforces the version: ${regex}";
147148
fi;
148-
}
149+
};
149150

150151
# Curl wrapper to switch TLS option for each OS
151152
function curlw () {
@@ -163,13 +164,13 @@ function curlw () {
163164
fi;
164165

165166
curl ${TLS_OPT} ${NETRC_OPT} "$@";
166-
}
167+
};
167168
export -f curlw;
168169

169170
check_active_version() {
170171
local v="${1}";
171172
[ -n "$(${TFENV_ROOT}/bin/terraform version | grep -E "^Terraform v${v}((-dev)|( \([a-f0-9]+\)))?$")" ];
172-
}
173+
};
173174
export -f check_active_version;
174175

175176
check_installed_version() {

lib/tfenv-exec.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,5 @@ function tfenv-exec() {
3333
|| log 'error' "Failed to execute: ${TF_BIN_PATH} $*";
3434

3535
return 0;
36-
}
36+
};
3737
export -f tfenv-exec;

lib/tfenv-version-file.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ find_local_version_file() {
1414
done;
1515
log 'debug' "No version file found in ${1}";
1616
return 1;
17-
}
17+
};
1818
export -f find_local_version_file;
1919

2020
function tfenv-version-file() {
@@ -24,5 +24,5 @@ function tfenv-version-file() {
2424
echo "${TFENV_CONFIG_DIR}/version";
2525
fi;
2626
fi;
27-
}
27+
};
2828
export -f tfenv-version-file;

lib/tfenv-version-name.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ function tfenv-version-name() {
55
|| log 'error' 'Failed to retrieve TFENV_VERSION_FILE from tfenv-version-file';
66

77
if [ "${TFENV_VERSION_FILE}" = "${TFENV_CONFIG_DIR}/version" ]; then
8-
log 'debug' 'Tryng to set version from "required_version" under "terraform" section'
8+
log 'debug' 'Tryng to set version from "required_version" under "terraform" section';
99

1010
versions="$( echo $(cat {*.tf,*.tf.json} 2>/dev/null | grep -h required_version) | grep -o '\([0-9]\+\.\?\)\{2,3\}\(-[a-z]\+[0-9]\+\)\?')";
1111
if [[ "${versions}" =~ ([~=!<>]{0,2}[[:blank:]]*[0-9]+[0-9.]+)[^0-9]*(-[a-z]+[0-9]+)? ]]; then
12-
found_min_required="${BASH_REMATCH[1]}${BASH_REMATCH[2]}"
12+
found_min_required="${BASH_REMATCH[1]}${BASH_REMATCH[2]}";
1313
if [[ "${found_min_required}" =~ ^!=.+ ]]; then
1414
log 'debug' "required_version is a negation - we cannot guess the desired one, skipping.";
1515
else
@@ -25,7 +25,7 @@ function tfenv-version-name() {
2525
fi;
2626
fi;
2727

28-
TFENV_VERSION_SOURCE='terraform{required_version}'
28+
TFENV_VERSION_SOURCE='terraform{required_version}';
2929
fi;
3030

3131
if [[ -z "${TFENV_VERSION:-""}" ]]; then
@@ -89,7 +89,7 @@ function tfenv-version-name() {
8989

9090
# Accept a v-prefixed version, but strip the v.
9191
if [[ "${TFENV_VERSION}" =~ ^v.*$ ]]; then
92-
log 'debug' "Version Requested is prefixed with a v. Stripping the v."
92+
log 'debug' "Version Requested is prefixed with a v. Stripping the v.";
9393
TFENV_VERSION="${TFENV_VERSION#v*}";
9494
fi;
9595
fi;
@@ -103,6 +103,6 @@ function tfenv-version-name() {
103103
fi;
104104

105105
echo "${TFENV_VERSION}";
106-
}
106+
};
107107
export -f tfenv-version-name;
108108

libexec/tfenv---version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ fi;
5757
for dir in libexec bin; do
5858
case ":${PATH}:" in
5959
*:${TFENV_ROOT}/${dir}:*) log 'debug' "\$PATH already contains '${TFENV_ROOT}/${dir}', not adding it again";;
60-
*)
60+
*)
6161
log 'debug' "\$PATH does not contain '${TFENV_ROOT}/${dir}', prepending and exporting it now";
6262
export PATH="${TFENV_ROOT}/${dir}:${PATH}";
6363
;;

libexec/tfenv-exec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ fi;
6161
for dir in libexec bin; do
6262
case ":${PATH}:" in
6363
*:${TFENV_ROOT}/${dir}:*) log 'debug' "\$PATH already contains '${TFENV_ROOT}/${dir}', not adding it again";;
64-
*)
64+
*)
6565
log 'debug' "\$PATH does not contain '${TFENV_ROOT}/${dir}', prepending and exporting it now";
6666
export PATH="${TFENV_ROOT}/${dir}:${PATH}";
6767
;;
@@ -72,4 +72,4 @@ done;
7272
# Begin Script Body #
7373
#####################
7474

75-
tfenv-exec "$@"
75+
tfenv-exec "$@";

libexec/tfenv-init

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env bash
22

3-
[ -n "${TFENV_DEBUG}" ] && set -x
3+
[ -n "${TFENV_DEBUG}" ] && set -x:
44

5-
export PATH="${TFENV_ROOT}/bin:${PATH}"
5+
export PATH="${TFENV_ROOT}/bin:${PATH}";

0 commit comments

Comments
 (0)