2019-11-27 01:24:29 -07:00
|
|
|
# -*- sh -*-
|
|
|
|
|
2016-04-24 08:11:33 -07:00
|
|
|
version_command() {
|
|
|
|
local cmd=$1
|
2020-02-13 23:21:58 -07:00
|
|
|
local plugin_name=$2
|
2016-04-24 08:11:33 -07:00
|
|
|
|
2016-08-29 23:46:14 -07:00
|
|
|
if [ "$#" -lt "3" ]; then
|
2018-10-19 17:29:31 -07:00
|
|
|
if [ "$cmd" = "global" ]; then
|
2020-09-21 15:27:52 -07:00
|
|
|
printf "Usage: asdf global <name> <version>\\n"
|
2018-10-19 17:29:31 -07:00
|
|
|
else
|
2020-09-21 15:27:52 -07:00
|
|
|
printf "Usage: asdf local <name> <version>\\n"
|
2018-10-19 17:29:31 -07:00
|
|
|
fi
|
2016-04-24 08:11:33 -07:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2016-08-29 23:46:14 -07:00
|
|
|
shift 2
|
2017-09-04 10:04:56 -07:00
|
|
|
local versions=("$@")
|
2016-08-29 23:46:14 -07:00
|
|
|
|
|
|
|
local file
|
2018-02-12 16:41:27 -07:00
|
|
|
if [ "$cmd" = "global" ]; then
|
2017-09-14 04:21:36 -07:00
|
|
|
file=${ASDF_DEFAULT_TOOL_VERSIONS_FILENAME:-$HOME/.tool-versions}
|
2018-10-19 17:29:31 -07:00
|
|
|
elif [ "$cmd" = "local-tree" ]; then
|
|
|
|
file=$(find_tool_versions)
|
|
|
|
else # cmd = local
|
2017-09-04 10:04:56 -07:00
|
|
|
file="$(pwd)/.tool-versions"
|
2016-05-13 19:11:16 -07:00
|
|
|
fi
|
|
|
|
|
2018-06-16 19:59:37 -07:00
|
|
|
if [ -L "$file" ]; then
|
2019-11-29 09:15:38 -07:00
|
|
|
# Resolve file path if symlink
|
|
|
|
file="$(resolve_symlink "$file")"
|
2018-06-16 19:59:37 -07:00
|
|
|
fi
|
|
|
|
|
2020-02-13 23:21:58 -07:00
|
|
|
check_if_plugin_exists "$plugin_name"
|
2017-09-04 10:04:56 -07:00
|
|
|
|
2020-09-18 22:37:52 -07:00
|
|
|
declare -a resolved_versions
|
2017-09-04 10:04:56 -07:00
|
|
|
local version
|
|
|
|
for version in "${versions[@]}"; do
|
2020-09-18 22:37:52 -07:00
|
|
|
if [ "$version" = "latest" ]; then
|
|
|
|
version=$(asdf latest "$plugin_name")
|
|
|
|
fi
|
2020-08-28 16:09:22 -07:00
|
|
|
if ! (check_if_version_exists "$plugin_name" "$version"); then
|
|
|
|
version_not_installed_text "$plugin_name" "$version" 1>&2
|
|
|
|
exit 1
|
|
|
|
fi
|
2020-09-18 22:37:52 -07:00
|
|
|
resolved_versions+=("$version")
|
2016-08-29 23:46:14 -07:00
|
|
|
done
|
2016-04-24 08:11:33 -07:00
|
|
|
|
2020-02-13 23:21:58 -07:00
|
|
|
if [ -f "$file" ] && grep "^$plugin_name " "$file" >/dev/null; then
|
2020-09-18 22:37:52 -07:00
|
|
|
sed -i.bak -e "s|^$plugin_name .*$|$plugin_name ${resolved_versions[*]}|" "$file"
|
2017-10-27 07:27:27 -07:00
|
|
|
rm "$file".bak
|
2016-04-24 08:11:33 -07:00
|
|
|
else
|
2020-09-21 15:27:52 -07:00
|
|
|
printf "%s %s\\n" "$plugin_name" "${resolved_versions[*]}" >>"$file"
|
2016-04-24 08:11:33 -07:00
|
|
|
fi
|
|
|
|
}
|