mirror of
https://github.com/asdf-vm/asdf.git
synced 2024-11-15 01:28:17 -07:00
Cleanup utils
This commit is contained in:
parent
0693de24ce
commit
c175f20bc0
65
lib/utils.sh
65
lib/utils.sh
@ -13,31 +13,6 @@ asdf_dir() {
|
||||
}
|
||||
|
||||
|
||||
run_callback_if_command() {
|
||||
if [ "$1" = "$2" ]
|
||||
then
|
||||
$3 ${@:4}
|
||||
exit 0
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
list_package_installs() {
|
||||
local package=$1
|
||||
local package_installs_path=$(asdf_dir)/installs/${package}
|
||||
|
||||
if [ -d $package_installs_path ]
|
||||
then
|
||||
#TODO check if dir is empty and show message here too
|
||||
for install in ${package_installs_path}/*/; do
|
||||
echo "$(basename $install)"
|
||||
done
|
||||
else
|
||||
echo 'Oohes nooes ~! Nothing found'
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
get_install_path() {
|
||||
local package=$1
|
||||
local install_type=$2
|
||||
@ -73,46 +48,6 @@ get_source_path() {
|
||||
}
|
||||
|
||||
|
||||
write_shim_script() {
|
||||
local package=$1
|
||||
local version=$2
|
||||
local executable_path=$3
|
||||
local shim_path=$(asdf_dir)/shims/$(basename $executable_path)
|
||||
|
||||
echo """#!/usr/bin/env sh
|
||||
asdf exec ${package} $executable_path \${@:1}
|
||||
""" > $shim_path
|
||||
|
||||
chmod +x $shim_path
|
||||
}
|
||||
|
||||
|
||||
generate_shims_for_version() {
|
||||
local package=$1
|
||||
local full_version=$2
|
||||
local source_path=$(get_source_path $package)
|
||||
check_if_source_exists $source_path
|
||||
|
||||
IFS=':' read -a version_info <<< "$full_version"
|
||||
if [ "${version_info[0]}" = "tag" ] || [ "${version_info[0]}" = "commit" ]
|
||||
then
|
||||
local install_type="${version_info[0]}"
|
||||
local version="${version_info[1]}"
|
||||
else
|
||||
local install_type="version"
|
||||
local version="${version_info[0]}"
|
||||
fi
|
||||
|
||||
local space_seperated_list_of_executables=$(sh ${source_path}/bin/list-executables $package $install_type $version "${@:2}")
|
||||
IFS=' ' read -a all_executables <<< "$space_seperated_list_of_executables"
|
||||
|
||||
for executable in "${all_executables[@]}"
|
||||
do
|
||||
write_shim_script $package $version $executable
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
display_error() {
|
||||
echo $1
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user