Merge pull request #51 from tuvistavie/use-multiple-versions

Make it possible to use fallback versions. Thank you @tuvistavie ~!
This commit is contained in:
Akash Manohar 2016-05-14 15:19:29 +05:30
commit c3765182f8
4 changed files with 48 additions and 49 deletions

View File

@ -15,50 +15,53 @@ if [ "$full_version" == "" ]; then
exit -1
fi
IFS=' ' read -a versions <<< "$full_version"
IFS=':' read -a version_info <<< "$full_version"
if [ "${version_info[0]}" = "ref" ]; then
install_type="${version_info[0]}"
version="${version_info[1]}"
install_path=$(get_install_path $plugin_name $install_type $version)
elif [ "${version_info[0]}" = "path" ]; then
# This is for people who have the local source already compiled
# Like those who work on the language, etc
# We'll allow specifying path:/foo/bar/project in .tool-versions
# And then use the binaries there
install_type="path"
version="path"
install_path="${version_info[1]}"
else
install_type="version"
version="${version_info[0]}"
install_path=$(get_install_path $plugin_name $install_type $version)
fi
for version in "${versions[@]}"; do
IFS=':' read -a version_info <<< "$version"
if [ "${version_info[0]}" = "ref" ]; then
install_type="${version_info[0]}"
version="${version_info[1]}"
install_path=$(get_install_path $plugin_name $install_type $version)
elif [ "${version_info[0]}" = "path" ]; then
# This is for people who have the local source already compiled
# Like those who work on the language, etc
# We'll allow specifying path:/foo/bar/project in .tool-versions
# And then use the binaries there
install_type="path"
version="path"
install_path="${version_info[1]}"
else
install_type="version"
version="${version_info[0]}"
install_path=$(get_install_path $plugin_name $install_type $version)
fi
if [ ! -d $install_path ]; then
echo "$plugin_name $full_version not installed"
exit 1
fi
if [ ! -d $install_path ]; then
echo "$plugin_name $version not installed"
exit 1
fi
if [ ! -f ${install_path}/${executable_path} ]; then
echo "No such command in $full_version of $plugin_name"
exit 1
fi
if [ -f ${install_path}/${executable_path} ]; then
if [ -f ${plugin_path}/bin/exec-env ]; then
export ASDF_INSTALL_TYPE=$install_type
export ASDF_INSTALL_VERSION=$version
export ASDF_INSTALL_PATH=$install_path
source ${plugin_path}/bin/exec-env
if [ -f ${plugin_path}/bin/exec-env ]; then
export ASDF_INSTALL_TYPE=$install_type
export ASDF_INSTALL_VERSION=$version
export ASDF_INSTALL_PATH=$install_path
# unset everything, we don't want to pollute
unset ASDF_INSTALL_TYPE
unset ASDF_INSTALL_VERSION
unset ASDF_INSTALL_PATH
exec ${install_path}/${executable_path} "${@:3}"
else
exec ${install_path}/${executable_path} "${@:3}"
fi
fi
done
source ${plugin_path}/bin/exec-env
# unset everything, we don't want to pollute
unset ASDF_INSTALL_TYPE
unset ASDF_INSTALL_VERSION
unset ASDF_INSTALL_PATH
exec ${install_path}/${executable_path} "${@:3}"
else
exec ${install_path}/${executable_path} "${@:3}"
fi
echo "No such command in $full_version of $plugin_name"
exit 1

View File

@ -81,12 +81,12 @@ complete -f -c asdf -n '__fish_asdf_using_command reshim; and __fish_asdf_arg_nu
# local completion
complete -f -c asdf -n '__fish_asdf_needs_command' -a local -d "Set local version for a plugin"
complete -f -c asdf -n '__fish_asdf_using_command local; and __fish_asdf_arg_number 2' -a '(asdf plugin-list)'
complete -f -c asdf -n '__fish_asdf_using_command local; and __fish_asdf_arg_number 3' -a '(asdf list (__fish_asdf_arg_at 3))'
complete -f -c asdf -n '__fish_asdf_using_command local; and test (count (commandline -opc)) -gt 2' -a '(asdf list (__fish_asdf_arg_at 3))'
# global completion
complete -f -c asdf -n '__fish_asdf_needs_command' -a global -d "Set global version for a plugin"
complete -f -c asdf -n '__fish_asdf_using_command global; and __fish_asdf_arg_number 2' -a '(asdf plugin-list)'
complete -f -c asdf -n '__fish_asdf_using_command global; and __fish_asdf_arg_number 3' -a '(asdf list (__fish_asdf_arg_at 3))'
complete -f -c asdf -n '__fish_asdf_using_command global; and test (count (commandline -opc)) -gt 2' -a '(asdf list (__fish_asdf_arg_at 3))'
# misc
complete -f -c asdf -n '__fish_asdf_needs_command' -l "help" -d "Displays help"

View File

@ -31,11 +31,6 @@ get_plugin_version() {
version_command() {
local cmd=$1
if [ $# -gt 3 ]; then
echo usage: $cmd [PLUGIN] [VERSION]
exit 1
fi
local file
if [ $cmd = "global" ]; then
file=$HOME/.tool-versions
@ -64,7 +59,7 @@ version_command() {
get_plugin_version $cmd $file $plugin
fi
local version=$3
local version=${@:3}
if [ $cmd = "local" ]; then
file=$(pwd)/.tool-versions

View File

@ -116,6 +116,7 @@ get_preset_version_for() {
get_tool_version_from_file() {
local asdf_versions_path=$1
local tool_name=$2
local get_all_versions=$3
local matching_tool_version=""
local read_done=false
@ -128,7 +129,7 @@ get_tool_version_from_file() {
IFS=' ' read -a tool_info <<< $tool_line
local t_name=$(echo "${tool_info[0]}" | xargs)
local t_version=$(echo "${tool_info[1]}" | xargs)
local t_version=$(echo "${tool_info[@]:1}" | xargs)
if [ "$t_name" = "$tool_name" ]
then