Add reshim command

This commit is contained in:
Akash Manohar J 2014-12-14 13:43:43 +05:30
parent 9c3171a726
commit 7f86587353
3 changed files with 106 additions and 3 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
installs
sources
shims

View File

@ -10,20 +10,70 @@ run_command() {
run_callback_if_command "source-remove" $1 source_remove_command $callback_args
run_callback_if_command "source-update" $1 source_update_command $callback_args
run_callback_if_command "reshim" $1 reshim_command $callback_args
run_callback_if_command "help" $1 help_command $callback_args
run_callback_if_command "exec" $1 exec_command $callback_args
run_callback_if_command "help" $1 help_command $callback_args
help_command
exit 1
}
exec_command() {
local package=$1
local executable_path=$2
#TODO support .versions file
local full_version=$ASDF_PACKAGE_VERSION
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 install_path=$(get_install_path $package $install_type $version)
exec ${install_path}/${executable_path} ${@:3}
}
reshim_command() {
local package=$1
local version=$2
local source_path=$(get_source_path $package)
check_if_source_exists $source_path
local package_installs_path=$(asdf_dir)/installs/${package}
if [ $version = "" ]
then
#TODO add support to parse "tag-$version" dir names to what we want
for install in ${package_installs_path}/*/; do
echo "TODO"
echo "$(basename $install)"
done
else
generate_shims_for_version $package $version "${@:3}"
fi
}
install_command() {
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"
@ -38,6 +88,7 @@ install_command() {
local install_path=$(get_install_path $package $install_type $version)
${source_path}/bin/install $install_type $version $install_path "${@:3}"
#TODO generate shims
}

View File

@ -44,7 +44,12 @@ get_install_path() {
local version=$3
mkdir -p $(asdf_dir)/installs/${package}
echo $(asdf_dir)/installs/${package}/${install_type}-${version}
if [ $install_type = "version" ]
then
echo $(asdf_dir)/installs/${package}/${version}
else
echo $(asdf_dir)/installs/${package}/${install_type}-${version}
fi
}
@ -57,11 +62,57 @@ check_if_source_exists() {
}
get_version_part() {
IFS='@' read -a version_info <<< "$1"
echo ${version_info[$2]}
}
get_source_path() {
echo $(asdf_dir)/sources/$1
}
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
}