Skip to content

Commit

Permalink
Editor formatting changes
Browse files Browse the repository at this point in the history
  • Loading branch information
seanhagen committed Aug 28, 2024
1 parent cf0df0a commit 8a8176d
Showing 1 changed file with 47 additions and 47 deletions.
94 changes: 47 additions & 47 deletions lib/utils.bash
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,41 @@ TOOL_NAME="protolint"
TOOL_TEST="protolint --help"

fail() {
echo -e "asdf-$TOOL_NAME: $*"
exit 1
echo -e "asdf-$TOOL_NAME: $*"
exit 1
}

curl_opts=(-fsSL)

if [ -n "${GITHUB_API_TOKEN:-}" ]; then
curl_opts=("${curl_opts[@]}" -H "Authorization: token $GITHUB_API_TOKEN")
curl_opts=("${curl_opts[@]}" -H "Authorization: token $GITHUB_API_TOKEN")
fi

sort_versions() {
sed 'h; s/[+-]/./g; s/.p\([[:digit:]]\)/.z\1/; s/$/.z/; G; s/\n/ /' |
LC_ALL=C sort -t. -k 1,1 -k 2,2n -k 3,3n -k 4,4n -k 5,5n | awk '{print $2}'
sed 'h; s/[+-]/./g; s/.p\([[:digit:]]\)/.z\1/; s/$/.z/; G; s/\n/ /' |
LC_ALL=C sort -t. -k 1,1 -k 2,2n -k 3,3n -k 4,4n -k 5,5n | awk '{print $2}'
}

list_github_tags() {
git ls-remote --tags --refs "$GH_REPO" |
grep -o 'refs/tags/.*' | cut -d/ -f3- |
sed 's/^v//'
git ls-remote --tags --refs "$GH_REPO" |
grep -o 'refs/tags/.*' | cut -d/ -f3- |
sed 's/^v//'
}

list_all_versions() {
list_github_tags
list_github_tags
}

get_platform() {
if [[ $(uname -s) == "Darwin" ]]; then
_plat="$(uname | tr '[:upper:]' '[:lower:]')"
echo "$_plat"
elif [[ $(uname -s) == "Linux" ]]; then
_plat="$(uname | tr '[:upper:]' '[:lower:]')"
echo "$_plat"
else
echo >&2 'Platform not supported' && exit 1
fi
if [[ $(uname -s) == "Darwin" ]]; then
_plat="$(uname | tr '[:upper:]' '[:lower:]')"
echo "$_plat"
elif [[ $(uname -s) == "Linux" ]]; then
_plat="$(uname | tr '[:upper:]' '[:lower:]')"
echo "$_plat"
else
echo >&2 'Platform not supported' && exit 1
fi
}

# from https://stackoverflow.com/questions/4023830/how-to-compare-two-strings-in-dot-separated-version-format-in-bash
Expand Down Expand Up @@ -84,38 +84,38 @@ get_arch() {
}

download_release() {
local version filename url
version="$1"
filename="$2"
platform="$3"
arch="$4"
local version filename url
version="$1"
filename="$2"
platform="$3"
arch="$4"

url="$GH_REPO/releases/download/v${version}/${TOOL_NAME}_${version}_${platform}_${arch}.tar.gz"
url="$GH_REPO/releases/download/v${version}/${TOOL_NAME}_${version}_${platform}_${arch}.tar.gz"

echo "* Downloading $TOOL_NAME release $version..."
curl "${curl_opts[@]}" -o "$filename" -C - "$url" || fail "Could not download $url"
echo "* Downloading $TOOL_NAME release $version..."
curl "${curl_opts[@]}" -o "$filename" -C - "$url" || fail "Could not download $url"
}

install_version() {
local install_type="$1"
local version="$2"
local install_path="$3"

if [ "$install_type" != "version" ]; then
fail "asdf-$TOOL_NAME supports release installs only"
fi

(
mkdir -p "$install_path/bin"
cp "$ASDF_DOWNLOAD_PATH/$TOOL_NAME" "$install_path/bin"

local tool_cmd
tool_cmd="$(echo "$TOOL_TEST" | cut -d' ' -f1)"
test -x "$install_path/bin/$tool_cmd" || fail "Expected $install_path/bin/$tool_cmd to be executable."

echo "$TOOL_NAME $version installation was successful!"
) || (
rm -rf "$install_path"
fail "An error ocurred while installing $TOOL_NAME $version."
)
local install_type="$1"
local version="$2"
local install_path="$3"

if [ "$install_type" != "version" ]; then
fail "asdf-$TOOL_NAME supports release installs only"
fi

(
mkdir -p "$install_path/bin"
cp "$ASDF_DOWNLOAD_PATH/$TOOL_NAME" "$install_path/bin"

local tool_cmd
tool_cmd="$(echo "$TOOL_TEST" | cut -d' ' -f1)"
test -x "$install_path/bin/$tool_cmd" || fail "Expected $install_path/bin/$tool_cmd to be executable."

echo "$TOOL_NAME $version installation was successful!"
) || (
rm -rf "$install_path"
fail "An error ocurred while installing $TOOL_NAME $version."
)
}

0 comments on commit 8a8176d

Please sign in to comment.