Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to read the crystal version from shard.yml file #56

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions bin/list-legacy-filenames
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
set -eo pipefail

echo ".crystal-version"
echo ".crystal-version shard.yml"
18 changes: 18 additions & 0 deletions bin/parse-legacy-file
Original file line number Diff line number Diff line change
@@ -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"