From 41022b5fe46d0f24d6b8c17cf9a68569aaaa4b60 Mon Sep 17 00:00:00 2001 From: Daniel Illi Date: Sun, 5 Feb 2023 11:14:28 +0100 Subject: [PATCH] Add support to read the crystal version from `shard.yml` file --- README.md | 10 ++++++---- bin/list-legacy-filenames | 1 + bin/parse-legacy-file | 18 ++++++++++++++++++ 3 files changed, 25 insertions(+), 4 deletions(-) create mode 100755 bin/parse-legacy-file diff --git a/README.md b/README.md index 4e4eac6..e3a5d29 100644 --- a/README.md +++ b/README.md @@ -22,10 +22,12 @@ install & manage versions. ## Useful information -asdf uses the `.tool-versions` for auto-switching between software versions. To -ease migration, you can have it read `.crystal-version` file to find out what -version of Crystal should be used. This only works with the exact version. To do -this, add the following to `~/.asdfrc`: +asdf uses the `.tool-versions` for auto-switching between software versions. +If `legacy_verison_file` support is enabled, it can read the crystal version +from `shard.yml`. To ease migration, it can also read the version from the +`.crystal-version` file. This only works with the exact version. + +To enable `legacy_verison_file` support, add the following to `~/.asdfrc`: ``` legacy_version_file = yes diff --git a/bin/list-legacy-filenames b/bin/list-legacy-filenames index 9838d80..68f78c2 100755 --- a/bin/list-legacy-filenames +++ b/bin/list-legacy-filenames @@ -3,3 +3,4 @@ set -eo pipefail echo ".crystal-version" +echo ".crystal-version shard.yml" diff --git a/bin/parse-legacy-file b/bin/parse-legacy-file new file mode 100755 index 0000000..f63ed1e --- /dev/null +++ b/bin/parse-legacy-file @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +get_legacy_version() { + current_file="$1" + basename="$(basename -- "$current_file")" + + if [ "$basename" == "shard.yml" ]; then + CRYSTAL_VERSION="$(grep '^crystal:' "$current_file" | + sed 's/crystal:[[:space:]]*//g' | + head -1)" + elif [ "$basename" == ".crystal-version" ]; then + CRYSTAL_VERSION="$(cat "$current_file")" + fi + + echo "$CRYSTAL_VERSION" +} + +get_legacy_version "$1"