diff --git a/README.md b/README.md index 3bc2a6e..8842bbf 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,8 @@ # Contents +- [asdf-scala-cli ](#asdf-scala-cli--) +- [Contents](#contents) - [Dependencies](#dependencies) - [Install](#install) - [Contributing](#contributing) @@ -15,10 +17,7 @@ # Dependencies -**TODO: adapt this section** - -- `bash`, `curl`, `tar`: generic POSIX utilities. -- `SOME_ENV_VAR`: set this environment variable in your shell config to load the correct version of tool x. +- `bash`, `curl`, `gzip`: generic POSIX utilities. # Install diff --git a/bin/download b/bin/download index c11ee53..fe61feb 100755 --- a/bin/download +++ b/bin/download @@ -10,14 +10,11 @@ source "${plugin_dir}/lib/utils.bash" mkdir -p "$ASDF_DOWNLOAD_PATH" -# TODO: Adapt this to proper extension and adapt extracting strategy. -release_file="$ASDF_DOWNLOAD_PATH/$TOOL_NAME-$ASDF_INSTALL_VERSION.tar.gz" +release_file="$ASDF_DOWNLOAD_PATH/$TOOL_NAME.gz" # Download tar.gz file to the download directory download_release "$ASDF_INSTALL_VERSION" "$release_file" # Extract contents of tar.gz file into the download directory -tar -xzf "$release_file" -C "$ASDF_DOWNLOAD_PATH" --strip-components=1 || fail "Could not extract $release_file" - -# Remove the tar.gz file since we don't need to keep it -rm "$release_file" +# tar -xzf "$release_file" -C "$ASDF_DOWNLOAD_PATH" --strip-components=1 || fail "Could not extract $release_file" +(pushd "$ASDF_DOWNLOAD_PATH" && gzip -d "$TOOL_NAME" && chmod +x "$TOOL_NAME" && popd )|| fail "Could not extract $release_file" diff --git a/contributing.md b/contributing.md index dba9b98..97aa798 100644 --- a/contributing.md +++ b/contributing.md @@ -5,8 +5,7 @@ Testing Locally: ```shell asdf plugin test [--asdf-tool-version ] [--asdf-plugin-gitref ] [test-command*] -# TODO: adapt this -asdf plugin test scala-cli https://github.com/rlemaitre/asdf-scala-cli.git "scala-cli --help" +asdf plugin test scala-cli https://github.com/rlemaitre/asdf-scala-cli.git "scala-cli version" ``` Tests are automatically run in GitHub Actions on push and PR. diff --git a/lib/utils.bash b/lib/utils.bash index 6130f33..86fe82c 100644 --- a/lib/utils.bash +++ b/lib/utils.bash @@ -2,10 +2,9 @@ set -euo pipefail -# TODO: Ensure this is the correct GitHub homepage where releases can be downloaded for scala-cli. GH_REPO="https://github.com/VirtusLab/scala-cli" TOOL_NAME="scala-cli" -TOOL_TEST="scala-cli --help" +TOOL_TEST="scala-cli version" fail() { echo -e "asdf-$TOOL_NAME: $*" @@ -31,18 +30,29 @@ list_github_tags() { } list_all_versions() { - # TODO: Adapt this. By default we simply list the tag names from GitHub releases. - # Change this function if scala-cli has other means of determining installable versions. list_github_tags } download_release() { - local version filename url + local version filename url arch os version="$1" filename="$2" - - # TODO: Adapt the release URL convention for scala-cli - url="$GH_REPO/archive/v${version}.tar.gz" + arch="$(uname -m)" + if [[ "$arch" == 'arm64' ]]; then + arch='aarch64' + else + arch='x86_64' + fi + os="$(uname -s)" + case $os in + 'Linux') + url="$GH_REPO/releases/download/v${version}/scala-cli-$arch-pc-linux.gz" + ;; + 'Darwin') + url="$GH_REPO/releases/download/v${version}/scala-cli-$arch-apple-darwin.gz" + ;; + *) ;; + esac echo "* Downloading $TOOL_NAME release $version..." curl "${curl_opts[@]}" -o "$filename" -C - "$url" || fail "Could not download $url" @@ -61,7 +71,6 @@ install_version() { mkdir -p "$install_path" cp -r "$ASDF_DOWNLOAD_PATH"/* "$install_path" - # TODO: Assert scala-cli executable exists. local tool_cmd tool_cmd="$(echo "$TOOL_TEST" | cut -d' ' -f1)" test -x "$install_path/$tool_cmd" || fail "Expected $install_path/$tool_cmd to be executable."