Skip to content

Commit 3e31c40

Browse files
author
Daniel Perez
committed
Make it possible to use fallback versions.
1 parent 0c36c00 commit 3e31c40

File tree

4 files changed

+47
-48
lines changed

4 files changed

+47
-48
lines changed

bin/private/asdf-exec

Lines changed: 42 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -15,50 +15,53 @@ if [ "$full_version" == "" ]; then
1515
exit -1
1616
fi
1717

18+
IFS=' ' read -a versions <<< "$full_version"
1819

19-
IFS=':' read -a version_info <<< "$full_version"
20-
if [ "${version_info[0]}" = "ref" ]; then
21-
install_type="${version_info[0]}"
22-
version="${version_info[1]}"
23-
install_path=$(get_install_path $plugin_name $install_type $version)
24-
elif [ "${version_info[0]}" = "path" ]; then
25-
# This is for people who have the local source already compiled
26-
# Like those who work on the language, etc
27-
# We'll allow specifying path:/foo/bar/project in .tool-versions
28-
# And then use the binaries there
29-
install_type="path"
30-
version="path"
31-
install_path="${version_info[1]}"
32-
else
33-
install_type="version"
34-
version="${version_info[0]}"
35-
install_path=$(get_install_path $plugin_name $install_type $version)
36-
fi
20+
for version in "${versions[@]}"; do
21+
IFS=':' read -a version_info <<< "$version"
3722

23+
if [ "${version_info[0]}" = "ref" ]; then
24+
install_type="${version_info[0]}"
25+
version="${version_info[1]}"
26+
install_path=$(get_install_path $plugin_name $install_type $version)
27+
elif [ "${version_info[0]}" = "path" ]; then
28+
# This is for people who have the local source already compiled
29+
# Like those who work on the language, etc
30+
# We'll allow specifying path:/foo/bar/project in .tool-versions
31+
# And then use the binaries there
32+
install_type="path"
33+
version="path"
34+
install_path="${version_info[1]}"
35+
else
36+
install_type="version"
37+
version="${version_info[0]}"
38+
install_path=$(get_install_path $plugin_name $install_type $version)
39+
fi
3840

39-
if [ ! -d $install_path ]; then
40-
echo "$plugin_name $full_version not installed"
41-
exit 1
42-
fi
4341

44-
if [ ! -f ${install_path}/${executable_path} ]; then
45-
echo "No such command in $full_version of $plugin_name"
46-
exit 1
47-
fi
42+
if [ ! -d $install_path ]; then
43+
echo "$plugin_name $version not installed"
44+
exit 1
45+
fi
4846

47+
if [ -f ${install_path}/${executable_path} ]; then
48+
if [ -f ${plugin_path}/bin/exec-env ]; then
49+
export ASDF_INSTALL_TYPE=$install_type
50+
export ASDF_INSTALL_VERSION=$version
51+
export ASDF_INSTALL_PATH=$install_path
4952

50-
if [ -f ${plugin_path}/bin/exec-env ]; then
51-
export ASDF_INSTALL_TYPE=$install_type
52-
export ASDF_INSTALL_VERSION=$version
53-
export ASDF_INSTALL_PATH=$install_path
53+
source ${plugin_path}/bin/exec-env
5454

55-
source ${plugin_path}/bin/exec-env
55+
# unset everything, we don't want to pollute
56+
unset ASDF_INSTALL_TYPE
57+
unset ASDF_INSTALL_VERSION
58+
unset ASDF_INSTALL_PATH
59+
exec ${install_path}/${executable_path} "${@:3}"
60+
else
61+
exec ${install_path}/${executable_path} "${@:3}"
62+
fi
63+
fi
64+
done
5665

57-
# unset everything, we don't want to pollute
58-
unset ASDF_INSTALL_TYPE
59-
unset ASDF_INSTALL_VERSION
60-
unset ASDF_INSTALL_PATH
61-
exec ${install_path}/${executable_path} "${@:3}"
62-
else
63-
exec ${install_path}/${executable_path} "${@:3}"
64-
fi
66+
echo "No such command in $full_version of $plugin_name"
67+
exit 1

completions/asdf.fish

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,12 @@ complete -f -c asdf -n '__fish_asdf_using_command reshim; and __fish_asdf_arg_nu
8181
# local completion
8282
complete -f -c asdf -n '__fish_asdf_needs_command' -a local -d "Set local version for a plugin"
8383
complete -f -c asdf -n '__fish_asdf_using_command local; and __fish_asdf_arg_number 2' -a '(asdf plugin-list)'
84-
complete -f -c asdf -n '__fish_asdf_using_command local; and __fish_asdf_arg_number 3' -a '(asdf list (__fish_asdf_arg_at 3))'
84+
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))'
8585

8686
# global completion
8787
complete -f -c asdf -n '__fish_asdf_needs_command' -a global -d "Set global version for a plugin"
8888
complete -f -c asdf -n '__fish_asdf_using_command global; and __fish_asdf_arg_number 2' -a '(asdf plugin-list)'
89-
complete -f -c asdf -n '__fish_asdf_using_command global; and __fish_asdf_arg_number 3' -a '(asdf list (__fish_asdf_arg_at 3))'
89+
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))'
9090

9191
# misc
9292
complete -f -c asdf -n '__fish_asdf_needs_command' -l "help" -d "Displays help"

lib/commands/version_commands.sh

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,6 @@ get_plugin_version() {
3131
version_command() {
3232
local cmd=$1
3333

34-
if [ $# -gt 3 ]; then
35-
echo usage: $cmd [PLUGIN] [VERSION]
36-
exit 1
37-
fi
38-
3934
local file
4035
if [ $cmd = "global" ]; then
4136
file=$HOME/.tool-versions
@@ -64,7 +59,7 @@ version_command() {
6459
get_plugin_version $cmd $file $plugin
6560
fi
6661

67-
local version=$3
62+
local version=${@:3}
6863

6964
check_if_version_exists $plugin $version
7065

lib/utils.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ get_preset_version_for() {
116116
get_tool_version_from_file() {
117117
local asdf_versions_path=$1
118118
local tool_name=$2
119+
local get_all_versions=$3
119120
local matching_tool_version=""
120121

121122
local read_done=false
@@ -128,7 +129,7 @@ get_tool_version_from_file() {
128129

129130
IFS=' ' read -a tool_info <<< $tool_line
130131
local t_name=$(echo "${tool_info[0]}" | xargs)
131-
local t_version=$(echo "${tool_info[1]}" | xargs)
132+
local t_version=$(echo "${tool_info[@]:1}" | xargs)
132133

133134
if [ "$t_name" = "$tool_name" ]
134135
then

0 commit comments

Comments
 (0)