2014-11-29 09:28:11 -07:00
|
|
|
asdf_version() {
|
2016-08-04 16:11:26 -07:00
|
|
|
echo "0.2.0-dev"
|
2014-11-29 09:28:11 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
asdf_dir() {
|
2015-05-17 02:09:18 -07:00
|
|
|
if [ -z $ASDF_DIR ]; then
|
|
|
|
local current_script_path=${BASH_SOURCE[0]}
|
|
|
|
export ASDF_DIR=$(cd $(dirname $(dirname $current_script_path)); echo $(pwd))
|
2014-11-29 23:02:57 -07:00
|
|
|
fi
|
|
|
|
|
|
|
|
echo $ASDF_DIR
|
2014-11-29 09:28:11 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-12-13 09:26:56 -07:00
|
|
|
get_install_path() {
|
2015-05-29 09:24:31 -07:00
|
|
|
local plugin=$1
|
2014-12-13 09:26:56 -07:00
|
|
|
local install_type=$2
|
|
|
|
local version=$3
|
2015-05-29 09:24:31 -07:00
|
|
|
mkdir -p $(asdf_dir)/installs/${plugin}
|
2014-12-13 09:26:56 -07:00
|
|
|
|
2014-12-14 01:13:43 -07:00
|
|
|
if [ $install_type = "version" ]
|
|
|
|
then
|
2015-05-29 09:24:31 -07:00
|
|
|
echo $(asdf_dir)/installs/${plugin}/${version}
|
2014-12-14 01:13:43 -07:00
|
|
|
else
|
2015-05-29 09:24:31 -07:00
|
|
|
echo $(asdf_dir)/installs/${plugin}/${install_type}-${version}
|
2014-12-14 01:13:43 -07:00
|
|
|
fi
|
2014-12-13 09:26:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-17 11:20:51 -07:00
|
|
|
check_if_plugin_exists() {
|
2016-07-05 16:19:15 -07:00
|
|
|
# Check if we have a non-empty argument
|
|
|
|
if [ -z "${1+set}" ]; then
|
|
|
|
display_error "No such plugin"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -d $(asdf_dir)/plugins/$1 ]; then
|
2015-05-17 11:20:51 -07:00
|
|
|
display_error "No such plugin"
|
2014-11-29 09:28:11 -07:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2016-04-24 08:11:33 -07:00
|
|
|
check_if_version_exists() {
|
|
|
|
local plugin=$1
|
|
|
|
local version=$2
|
|
|
|
local version_dir=$(asdf_dir)/installs/$plugin/$version
|
|
|
|
if [ ! -d $version_dir ]; then
|
|
|
|
display_error "version $version is not installed for $plugin"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2014-11-29 09:28:11 -07:00
|
|
|
|
2014-12-14 01:13:43 -07:00
|
|
|
get_version_part() {
|
|
|
|
IFS='@' read -a version_info <<< "$1"
|
|
|
|
echo ${version_info[$2]}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-17 11:20:51 -07:00
|
|
|
get_plugin_path() {
|
|
|
|
echo $(asdf_dir)/plugins/$1
|
2014-11-29 09:28:11 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
display_error() {
|
2016-07-05 16:19:15 -07:00
|
|
|
echo >&2 $1
|
2014-11-29 09:28:11 -07:00
|
|
|
}
|
2015-05-14 03:13:04 -07:00
|
|
|
|
2016-07-24 08:47:17 -07:00
|
|
|
get_version_file_path_for() {
|
|
|
|
local tool_name=$1
|
|
|
|
local legacy_version_file_support=$(get_asdf_config_value "legacy_version_file")
|
|
|
|
|
|
|
|
if [ ! -f "$(pwd)/.tool-versions" ] && [ "$legacy_version_file_support" = "yes" ]; then
|
|
|
|
# Check for legacy version and return "" if it exists
|
|
|
|
local legacy_version=$(get_tool_version_from_legacy_file $tool_name $(pwd))
|
|
|
|
if [ "$legacy_version" != "" ]; then
|
|
|
|
echo ""
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo $(get_asdf_versions_file_path)
|
|
|
|
}
|
2015-05-14 03:13:04 -07:00
|
|
|
|
|
|
|
get_asdf_versions_file_path() {
|
2015-05-14 21:36:21 -07:00
|
|
|
local asdf_tool_versions_path=""
|
|
|
|
local search_path=$(pwd)
|
|
|
|
|
|
|
|
while [ "$search_path" != "/" ]; do
|
2015-05-17 10:51:23 -07:00
|
|
|
if [ -f "$search_path/.tool-versions" ]; then
|
|
|
|
asdf_tool_versions_path="$search_path/.tool-versions"
|
2015-05-14 21:36:21 -07:00
|
|
|
break
|
|
|
|
fi
|
2015-12-22 17:00:18 -07:00
|
|
|
search_path=$(dirname "$search_path")
|
2015-05-14 21:36:21 -07:00
|
|
|
done
|
|
|
|
|
|
|
|
echo $asdf_tool_versions_path
|
2015-05-14 03:13:04 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
get_preset_version_for() {
|
2015-06-24 07:03:25 -07:00
|
|
|
local tool_name=$1
|
2015-05-14 03:13:04 -07:00
|
|
|
local asdf_versions_path=$(get_asdf_versions_file_path)
|
2015-06-24 07:03:25 -07:00
|
|
|
local matching_tool_version=""
|
2016-04-24 16:32:18 -07:00
|
|
|
local legacy_version_file_support=$(get_asdf_config_value "legacy_version_file")
|
2015-05-14 03:13:04 -07:00
|
|
|
|
2015-11-28 15:27:54 -07:00
|
|
|
# If .tool-versions is not in the working directory
|
2016-04-24 16:32:18 -07:00
|
|
|
if [ "$asdf_versions_path" != "$(pwd)/.tool-versions" ] && [ "$legacy_version_file_support" = "yes" ]; then
|
2015-11-28 15:27:54 -07:00
|
|
|
# Check for legacy version file
|
2016-02-13 08:30:34 -07:00
|
|
|
matching_tool_version=$(get_tool_version_from_legacy_file $tool_name $(pwd))
|
|
|
|
fi
|
2015-11-28 15:27:54 -07:00
|
|
|
|
2016-02-13 08:30:34 -07:00
|
|
|
# If no legacy version file, see if we can use a .tool-versions file higher in the directory tree
|
|
|
|
if [ "$matching_tool_version" = "" ] && [ "$asdf_versions_path" != "" ]; then
|
|
|
|
matching_tool_version=$(get_tool_version_from_file $asdf_versions_path $tool_name)
|
2015-06-24 06:46:49 -07:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
# If there's no global .tool-versions file
|
|
|
|
# then we create it and return blank
|
|
|
|
if [ "$matching_tool_version" = "" ]; then
|
|
|
|
local global_tool_versions_path=$HOME/.tool-versions
|
|
|
|
if [ ! -f $global_tool_versions_path ]; then
|
|
|
|
touch $global_tool_versions_path
|
|
|
|
else
|
2015-06-24 07:03:25 -07:00
|
|
|
matching_tool_version=$(get_tool_version_from_file $global_tool_versions_path $tool_name)
|
2015-06-24 06:46:49 -07:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
echo $matching_tool_version
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-24 07:03:25 -07:00
|
|
|
get_tool_version_from_file() {
|
|
|
|
local asdf_versions_path=$1
|
|
|
|
local tool_name=$2
|
2016-05-03 10:22:48 -07:00
|
|
|
local get_all_versions=$3
|
2015-06-24 06:46:49 -07:00
|
|
|
local matching_tool_version=""
|
|
|
|
|
2015-06-24 08:11:13 -07:00
|
|
|
local read_done=false
|
|
|
|
until $read_done; do
|
|
|
|
read tool_line || read_done=true
|
2015-06-24 10:13:15 -07:00
|
|
|
|
|
|
|
if $read_done ; then
|
|
|
|
break;
|
|
|
|
fi
|
|
|
|
|
2015-05-14 03:13:04 -07:00
|
|
|
IFS=' ' read -a tool_info <<< $tool_line
|
2015-06-24 07:03:25 -07:00
|
|
|
local t_name=$(echo "${tool_info[0]}" | xargs)
|
2016-05-03 10:22:48 -07:00
|
|
|
local t_version=$(echo "${tool_info[@]:1}" | xargs)
|
2015-05-14 03:13:04 -07:00
|
|
|
|
2015-06-24 07:03:25 -07:00
|
|
|
if [ "$t_name" = "$tool_name" ]
|
2015-05-17 02:09:18 -07:00
|
|
|
then
|
2015-06-24 07:03:25 -07:00
|
|
|
matching_tool_version=$t_version
|
2015-05-14 03:13:04 -07:00
|
|
|
break;
|
|
|
|
fi
|
|
|
|
done < $asdf_versions_path
|
|
|
|
|
2015-06-24 06:46:49 -07:00
|
|
|
echo $matching_tool_version
|
2015-05-14 03:13:04 -07:00
|
|
|
}
|
2015-11-28 15:27:54 -07:00
|
|
|
|
2016-04-24 16:18:12 -07:00
|
|
|
|
2015-11-28 15:27:54 -07:00
|
|
|
get_tool_version_from_legacy_file() {
|
|
|
|
local plugin_name=$1
|
2016-02-13 08:30:34 -07:00
|
|
|
local directory=$2
|
2015-11-28 15:27:54 -07:00
|
|
|
local legacy_tool_version=""
|
|
|
|
local plugin_path=$(get_plugin_path $plugin_name)
|
2016-02-13 08:32:35 -07:00
|
|
|
local legacy_version_script="${plugin_path}/bin/get-version-from-legacy-file"
|
2016-07-05 16:19:15 -07:00
|
|
|
check_if_plugin_exists $plugin_name
|
2015-11-28 15:27:54 -07:00
|
|
|
|
2016-02-13 12:10:58 -07:00
|
|
|
if [ -f $legacy_version_script ]; then
|
2016-02-13 08:30:34 -07:00
|
|
|
local legacy_tool_version=$(bash $legacy_version_script $directory)
|
2015-11-28 15:27:54 -07:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Should return the version/tag/commit/branch/path
|
|
|
|
echo $legacy_tool_version
|
|
|
|
}
|
2016-04-24 16:18:12 -07:00
|
|
|
|
|
|
|
|
2016-04-24 06:20:05 -07:00
|
|
|
get_asdf_config_value_from_file() {
|
|
|
|
local config_path=$1
|
|
|
|
local key=$2
|
|
|
|
|
|
|
|
if [ ! -f $config_path ]; then
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
local result=$(grep -E "^\s*$key\s*=" $config_path | awk -F '=' '{ gsub(/ /, "", $2); print $2 }')
|
|
|
|
if [ -n "$result" ]; then
|
|
|
|
echo $result
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
get_asdf_config_value() {
|
|
|
|
local key=$1
|
|
|
|
local config_path=${AZDF_CONFIG_FILE:-"$HOME/.asdfrc"}
|
|
|
|
local default_config_path=${AZDF_CONFIG_DEFAULT_FILE:-"$(asdf_dir)/defaults"}
|
|
|
|
|
|
|
|
local result=$(get_asdf_config_value_from_file $config_path $key)
|
|
|
|
|
|
|
|
if [ -n "$result" ]; then
|
|
|
|
echo $result
|
|
|
|
else
|
|
|
|
get_asdf_config_value_from_file $default_config_path $key
|
|
|
|
fi
|
|
|
|
}
|