Skip to content

Commit d253d2d

Browse files
Fail loudly on unmet pre-conditions (#12)
* Tweak some of the error messages * Use local consistently * Make sure we error out when pre-conditions aren't met
1 parent da26e56 commit d253d2d

File tree

2 files changed

+35
-15
lines changed

2 files changed

+35
-15
lines changed

bin/download

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ release_file="$downloadable-$ASDF_INSTALL_VERSION.tar.gz"
1717
download_release "$ASDF_INSTALL_VERSION" "$downloadable"
1818

1919
# Extract contents of tar.gz file into the download directory
20-
tar -xzf "$release_file" -C "$ASDF_DOWNLOAD_PATH" --strip-components=1 || fail "Could not extract $release_file"
20+
tar -xzf "$release_file" -C "$ASDF_DOWNLOAD_PATH" --strip-components=1 || fail "could not extract $release_file"
2121

2222
# Remove the tar.gz file since we don't need to keep it
2323
rm "$release_file"

lib/utils.bash

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ fail() {
1212
}
1313

1414
list_all_versions() {
15+
local current_script_path plugin_dir v
1516
current_script_path=${BASH_SOURCE[0]}
1617
plugin_dir=$(dirname "$(dirname "$current_script_path")")
1718
v="$plugin_dir/versions.txt"
@@ -27,22 +28,40 @@ list_all_versions() {
2728
}
2829

2930
download_release() {
30-
local version filename
31-
version="$1"
31+
local version dirname filename
32+
version=$1
3233
dirname=$(dirname "$2")
3334
filename=$(basename "$2")
3435

3536
printf "* Downloading %s release %s...\n" "$TOOL_NAME" "$version"
36-
pip3 download --dest "$dirname" "$filename==$version" || fail "Could not download from pip"
37+
ensure_pip3
38+
pip3 download --dest "$dirname" "$filename==$version" || fail "could not download from pip"
39+
}
40+
41+
ensure() {
42+
local check=$1
43+
local msg=$2
44+
45+
if ! eval "$check" >/dev/null; then
46+
fail "$msg (${check} == $?)"
47+
fi
48+
}
49+
50+
ensure_pip3() {
51+
ensure "which pip3" "it appears pip is not available"
52+
}
53+
54+
ensure_wheel() {
55+
ensure "pip show wheel" "it appears wheel is not available"
3756
}
3857

3958
install_version() {
40-
local install_type="$1"
41-
local version="$2"
42-
local install_path="$3"
59+
local install_type=$1
60+
local version=$2
61+
local install_path=$3
4362

4463
if [ "$install_type" != "version" ]; then
45-
fail "asdf-$TOOL_NAME supports release installs only"
64+
fail "supports release installs only"
4665
fi
4766

4867
(
@@ -56,17 +75,17 @@ install_version() {
5675
install_localstack "$install_path"
5776
unpack_deps "$install_path"
5877

59-
[ -x "$install_path/bin/$tool_cmd" ] || fail "Expected $install_path/$tool_cmd to be executable."
78+
[ -x "$install_path/bin/$tool_cmd" ] || fail "expected $install_path/$tool_cmd to be executable."
6079

6180
printf "%s %s installation was successful!\n" "$TOOL_NAME" "$version"
6281
) || (
6382
rm -rf "$install_path"
64-
fail "An error occurred while installing $TOOL_NAME $version."
83+
fail "an error occurred while installing $TOOL_NAME $version."
6584
)
6685
}
6786

6887
install_localstack() {
69-
install_path="$1"
88+
local install_path=$1
7089

7190
localstack_client_tar_gz=$(find "$install_path" -name "localstack-client*")
7291
tar zxf "$localstack_client_tar_gz" --strip-components=1 -C "$install_path"
@@ -76,8 +95,9 @@ install_localstack() {
7695
}
7796

7897
unpack_deps() {
79-
install_path="$1"
98+
local install_path=$1
8099

100+
ensure_wheel
81101
unpack_dep "$install_path" boto3 boto3
82102
unpack_dep "$install_path" botocore botocore
83103
unpack_dep "$install_path" jmespath jmespath
@@ -88,9 +108,9 @@ unpack_deps() {
88108
}
89109

90110
unpack_dep() {
91-
install_path="$1"
92-
dep="$2"
93-
dep_name="$3"
111+
local install_path=$1
112+
local dep=$2
113+
local dep_name=$3
94114

95115
dep_whl=$(find "$install_path" -name "$dep-*")
96116
wheel unpack "$dep_whl" --dest "$install_path"

0 commit comments

Comments
 (0)